I have these two dataframes:
df1 <-data.frame(v1=c("a","b"),v2=c("c","d"))
df2 <-data.frame(v1=c("a","b"),v2=c("c","d"))
I want to do a loop that creates a new variable (v3) that concatenates variables v1 and v2 for each dataframe, something like this:
for (i in 1:2) {
df[[i]]$v3 <- paste(a[[i]]$v1,a[[i]]$v2)
}
Thus, the final dataframe df1 would be:
| v1 | v2 | v3 |
|---|---|---|
| a | c | ac |
| b | d | bd |
And for df2 would be:
| v1 | v2 | v3 |
|---|---|---|
| a | c | ac |
| b | d | bd |