Re: [R] Combining Differnt columns in one single column

2022-06-13 Thread Ebert,Timothy Aaron
Sorry, the last post had a small mistake. I got name and val switched. Here 
they are in the correct order.

ID_names1 <- paste0("id",1:9)
ID_names2 <- paste0("id000",10:99)
ID5 <-as.data.frame(ID_names1)
ID5$name<-colnames(ID5)
colnames(ID5)<-c("val","name")
ID6 <-as.data.frame(ID_names2)
ID6$name<-colnames(ID6)
colnames(ID6)<-c("val","name")
IDall<-rbind(ID5,ID6)


Tim
-Original Message-
From: anteneh asmare  
Sent: Monday, June 13, 2022 4:49 PM
To: Ebert,Timothy Aaron 
Cc: r-help@r-project.org
Subject: Re: [R] Combining Differnt columns in one single column

[External Email]

Dear Tim it works, But i want to treat them as a column name. Is it possible to 
treat as a column name ?

Best,
Hana
On 6/13/22, Ebert,Timothy Aaron  wrote:
> ID5 <- as.data.frame(ID_names1)
> colnames(ID5)<-"val" #rename the columns so they have the same name.
> ID6 <- as.data.frame(ID_names2)
> colnames(ID6)<-"val"
> rbind(ID5, ID6)
>
> This works for the first two, just keep doing the same thing for the 
> others.
> Tim
>
> -----Original Message-
> From: R-help  On Behalf Of anteneh 
> asmare
> Sent: Monday, June 13, 2022 3:48 PM
> To: r-help@r-project.org
> Subject: [R] Combining Differnt columns in one single column
>
> [External Email]
>
> Dear All, I have the following column name in different data frame and 
> different size
> ID_names1 <- paste0("id",1:9)
> ID_names2 <- paste0("id000",10:99)
> ID_names3 <- paste0("id00",100:999)
> ID_names4 <- paste0("id0",1000:)
> ID_names5 <- paste0("id",1:5)
> Dose it possible to combine in to a single column in r?
> Best,
> Hana
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mail
> man_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAs
> Rzsn7AkP-g&m=cjCY0UmRewiKkMVVxNu2riO8k4tZHD7s7R3R6SC-bwEM5u77LyExCSIzw
> I-q7Xu_&s=xrZArAFWnJf7ja13EEgxwBj-pMBEXBYSQgc6BhtNPAA&e=
> PLEASE do read the posting guide
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.or
> g_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeA
> sRzsn7AkP-g&m=cjCY0UmRewiKkMVVxNu2riO8k4tZHD7s7R3R6SC-bwEM5u77LyExCSIz
> wI-q7Xu_&s=oUlYLeH_EF5rwea10resAheSjjvJ6nhUl8wT84OVXZM&e=
> and provide commented, minimal, self-contained, reproducible code.
>
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Combining Differnt columns in one single column

2022-06-13 Thread Ebert,Timothy Aaron
Yes, It just takes another step. Here is the new pattern:
ID_names1 <- paste0("id",1:9)
ID_names2 <- paste0("id000",10:99)
ID5 <-as.data.frame(ID_names1) #convert to a dataframe.
ID5$name<-colnames(ID5) #make a new variable from column name.
colnames(ID5)<-c("name","val") #rename columns to be consistent for all 
dataframes.
ID6 <-as.data.frame(ID_names2)
ID6$name<-colnames(ID6)
colnames(ID6)<-c("name","val")
IDall<-rbind(ID5,ID6) 


Tim

-Original Message-
From: anteneh asmare  
Sent: Monday, June 13, 2022 4:49 PM
To: Ebert,Timothy Aaron 
Cc: r-help@r-project.org
Subject: Re: [R] Combining Differnt columns in one single column

[External Email]

Dear Tim it works, But i want to treat them as a column name. Is it possible to 
treat as a column name ?

Best,
Hana
On 6/13/22, Ebert,Timothy Aaron  wrote:
> ID5 <- as.data.frame(ID_names1)
> colnames(ID5)<-"val" #rename the columns so they have the same name.
> ID6 <- as.data.frame(ID_names2)
> colnames(ID6)<-"val"
> rbind(ID5, ID6)
>
> This works for the first two, just keep doing the same thing for the 
> others.
> Tim
>
> -----Original Message-
> From: R-help  On Behalf Of anteneh 
> asmare
> Sent: Monday, June 13, 2022 3:48 PM
> To: r-help@r-project.org
> Subject: [R] Combining Differnt columns in one single column
>
> [External Email]
>
> Dear All, I have the following column name in different data frame and 
> different size
> ID_names1 <- paste0("id",1:9)
> ID_names2 <- paste0("id000",10:99)
> ID_names3 <- paste0("id00",100:999)
> ID_names4 <- paste0("id0",1000:)
> ID_names5 <- paste0("id",1:5)
> Dose it possible to combine in to a single column in r?
> Best,
> Hana
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mail
> man_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAs
> Rzsn7AkP-g&m=cjCY0UmRewiKkMVVxNu2riO8k4tZHD7s7R3R6SC-bwEM5u77LyExCSIzw
> I-q7Xu_&s=xrZArAFWnJf7ja13EEgxwBj-pMBEXBYSQgc6BhtNPAA&e=
> PLEASE do read the posting guide
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.or
> g_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeA
> sRzsn7AkP-g&m=cjCY0UmRewiKkMVVxNu2riO8k4tZHD7s7R3R6SC-bwEM5u77LyExCSIz
> wI-q7Xu_&s=oUlYLeH_EF5rwea10resAheSjjvJ6nhUl8wT84OVXZM&e=
> and provide commented, minimal, self-contained, reproducible code.
>
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Combining Differnt columns in one single column

2022-06-13 Thread Rui Barradas

Hello,

Are you looking for this?


ID_names <- sprintf("id%05d", 1:5)
head(ID_names)
#> [1] "id1" "id2" "id3" "id4" "id5" "id6"
tail(ID_names)
#> [1] "id49995" "id49996" "id49997" "id49998" "id4" "id5"


sprintf with the format %05d pads the integers with zeros to length 5.
And you won't need to combine the 5 vectors, it already is only one.

Hope this helps,

Rui Barradas

Às 20:48 de 13/06/2022, anteneh asmare escreveu:

Dear All, I have the following column name in different data frame and
different size
ID_names1 <- paste0("id",1:9)
ID_names2 <- paste0("id000",10:99)
ID_names3 <- paste0("id00",100:999)
ID_names4 <- paste0("id0",1000:)
ID_names5 <- paste0("id",1:5)
Dose it possible to combine in to a single column in r?
Best,
Hana

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Combining Differnt columns in one single column

2022-06-13 Thread anteneh asmare
Dear Tim it works, But i want to treat them as a column name. Is it
possible to treat as a column name ?

Best,
Hana
On 6/13/22, Ebert,Timothy Aaron  wrote:
> ID5 <- as.data.frame(ID_names1)
> colnames(ID5)<-"val" #rename the columns so they have the same name.
> ID6 <- as.data.frame(ID_names2)
> colnames(ID6)<-"val"
> rbind(ID5, ID6)
>
> This works for the first two, just keep doing the same thing for the
> others.
> Tim
>
> -Original Message-
> From: R-help  On Behalf Of anteneh asmare
> Sent: Monday, June 13, 2022 3:48 PM
> To: r-help@r-project.org
> Subject: [R] Combining Differnt columns in one single column
>
> [External Email]
>
> Dear All, I have the following column name in different data frame and
> different size
> ID_names1 <- paste0("id",1:9)
> ID_names2 <- paste0("id000",10:99)
> ID_names3 <- paste0("id00",100:999)
> ID_names4 <- paste0("id0",1000:)
> ID_names5 <- paste0("id",1:5)
> Dose it possible to combine in to a single column in r?
> Best,
> Hana
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=cjCY0UmRewiKkMVVxNu2riO8k4tZHD7s7R3R6SC-bwEM5u77LyExCSIzwI-q7Xu_&s=xrZArAFWnJf7ja13EEgxwBj-pMBEXBYSQgc6BhtNPAA&e=
> PLEASE do read the posting guide
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=cjCY0UmRewiKkMVVxNu2riO8k4tZHD7s7R3R6SC-bwEM5u77LyExCSIzwI-q7Xu_&s=oUlYLeH_EF5rwea10resAheSjjvJ6nhUl8wT84OVXZM&e=
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.