Dear All, I have the following column name in different data frame and
different size
ID_names1 <- paste0("id0000",1:9)
ID_names2 <- paste0("id000",10:99)
ID_names3 <- paste0("id00",100:999)
ID_names4 <- paste0("id0",1000:9999)
ID_names5 <- paste0("id",10000:50000)
Dose it possible to combine in to a single column in r?
Best,
Hana
Ebert,Timothy Aaron
2022-Jun-13 20:21 UTC
[R] Combining Differnt columns in one single column
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 <r-help-bounces at r-project.org> On Behalf Of anteneh asmare
Sent: Monday, June 13, 2022 3:48 PM
To: r-help at 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("id0000",1:9)
ID_names2 <- paste0("id000",10:99)
ID_names3 <- paste0("id00",100:999)
ID_names4 <- paste0("id0",1000:9999)
ID_names5 <- paste0("id",10000:50000)
Dose it possible to combine in to a single column in r?
Best,
Hana
______________________________________________
R-help at 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&ePLEASE
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&eand
provide commented, minimal, self-contained, reproducible code.
Hello,
Are you looking for this?
ID_names <- sprintf("id%05d", 1:50000)
head(ID_names)
#> [1] "id00001" "id00002" "id00003"
"id00004" "id00005" "id00006"
tail(ID_names)
#> [1] "id49995" "id49996" "id49997"
"id49998" "id49999" "id50000"
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("id0000",1:9)
> ID_names2 <- paste0("id000",10:99)
> ID_names3 <- paste0("id00",100:999)
> ID_names4 <- paste0("id0",1000:9999)
> ID_names5 <- paste0("id",10000:50000)
> Dose it possible to combine in to a single column in r?
> Best,
> Hana
>
> ______________________________________________
> R-help at 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.