I want  to "paste" the contents of the first column of a dataframe
with all the columns of the same dataframe.



What is a "good" way to do this, perhaps something more elegant than
what I have below.  (My actual dataframe has ~400 columns and ~35000
rows.)



example1:

mydf <- data.frame( matrix(data=1:15, nrow=5, ncol=3) )

mydf2 <- mydf

temp2 <- paste(unlist(mydf[,1]) , unlist(mydf), sep="_")

mydf2[ ,] <- temp2



example2:

mydf2 <- mydf



for(i in 1:ncol(mydf2) ) {

mydf2[i] <- paste( mydf[,1], mydf[ ,i], sep='_')

}

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to