Hello Friends!
I'm a begginer with R coding, and I need a help.
I have two data frames (df1 and dd), I would like to concatenate the entire column in df1 wih each value of dd. Using " / " separator.
x1<−rpois(7,5)
df1<−data.frame(x1)
dd<-data.frame("A","B","C","D","E","F")
Output should be:
7/A
6/A
8/A
4/A
3/A
4/A
3/A
7/B
6/B.... So on
Can you help me?
Thanks in advance.
FJCC
2
I would avoid a loop and use expand.grid().
x1<-rpois(7,5)
df1<-data.frame(x1)
dd<-data.frame(Let=c("A","B","C","D","E","F"))
library(tidyr)
FullGrid <- expand.grid(df1$x1,dd$Let)
FullGrid <- unite(FullGrid,col = "Output", Var1, Var2, sep = "/")
FullGrid
#> Output
#> 1 6/A
#> 2 4/A
#> 3 5/A
#> 4 6/A
#> 5 7/A
#> 6 7/A
#> 7 5/A
#> 8 6/B
#> 9 4/B
#> 10 5/B
#> 11 6/B
#> 12 7/B
#> 13 7/B
#> 14 5/B
#> 15 6/C
#> 16 4/C
#> 17 5/C
#> 18 6/C
#> 19 7/C
#> 20 7/C
#> 21 5/C
#> 22 6/D
#> 23 4/D
#> 24 5/D
#> 25 6/D
#> 26 7/D
#> 27 7/D
#> 28 5/D
#> 29 6/E
#> 30 4/E
#> 31 5/E
#> 32 6/E
#> 33 7/E
#> 34 7/E
#> 35 5/E
#> 36 6/F
#> 37 4/F
#> 38 5/F
#> 39 6/F
#> 40 7/F
#> 41 7/F
#> 42 5/F
Created on 2021-06-12 by the reprex package (v0.3.0)
Really Thank you!! It Worked.
system
Closed
4
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.