[R] Concatenating rows of a column vector

arun smartpink111 at yahoo.com
Sat Jan 11 21:31:02 CET 2014


Hi,
Try ?paste()
dat1 <- read.table(text="apkkaakafmfffakkannpaaapkacfaapfd
kpaaakaaaafkpkfbfakaaofakapkpppfcgaanfpfakaappffak
fkpkfbfakaaofakapkpppfcgaanfpfa
aakaaaafkpkfbfakaaofakapkpppfc",sep="",header=FALSE,stringsAsFactors=FALSE)

res <-  paste(dat1[,1],collapse="")
A.K.


So I have a 19x1 column vector. Each row of the column vector contains a string. For example, the (1,1) entry contains 
"apkkaakafmfffakkannpaaapkacfaapfd" and the (2,1) entry contains 
"kpaaakaaaafkpkfbfakaaofakapkpppfcgaanfpfakaappffak" and so on. 

How can I concatenate the rows so that I just have a 1 by 1 cell
 containing the strings from the first, second, third, ..., nineteenth 
row concatenated without any spaces between them? 

E.g., concatenating the first two rows should yield: 

"apkkaakafmfffakkannpaaapkacfaapfdkpaaakaaaafkpkfbfakaaofakapkpppfcgaanfpfakaappffak" 

Thanks.



More information about the R-help mailing list