Hi Arun: Thanks for your help. Seperate files are being created by concatenating the rows from the two files but I was looking to have them as columns rather than text. This is the way it appears in Excel with row # at the beginning. X Y1 Y2 1 1 4 0 20 17 1 20 52 15 18
Ideally I would like it to look like X Y1 Y2 1 4 20 1 0 52 1 20 15 1 17 18 Thanks again! Anamika On Mon, Oct 21, 2013 at 1:11 AM, arun <smartpink...@yahoo.com> wrote: > Hi, > May be this helps: > Y1 <- read.table(text="V1 V2 V3 V4 > 1 4 0 20 17 > 2 4 0 15 17 > 3 2 0 13 21",sep="",header=TRUE) > > Y2 <- read.table(text="V1 V2 V3 V4 > 1 20 52 15 18 > 2 18 54 14 21 > 3 18 51 13 21",sep="",header=TRUE) > res <- lapply(seq_len(nrow(Y1)),function(i) {dat <- > data.frame(X=i,Y1=unlist(Y1[i,]),Y2=unlist(Y2[i,])); row.names(dat) <- > 1:nrow(dat); > write.csv(dat,paste0("file",i,".csv"),row.names=FALSE,quote=FALSE)}) > > > A.K. > > > > > > A.K. > > > > > On Monday, October 21, 2013 12:24 AM, Anamika Chaudhuri < > canam...@gmail.com> wrote: > Hi: > > I am looking for some help to manipulate data in R. I have two csv files. > > datasetY1 > V1 "V2" "V3" "V4" > 1 4 0 20 17 > 2 4 0 15 17 > 3 2 0 13 21 > > datasetY2 > V1 "V2" "V3" "V4" > 1 20 52 15 18 > 2 18 54 14 21 > 3 18 51 13 21 > > I want to be able to create separate csv files by taking the corresponding > rows of dataset1 and dataset2, convert them into columns. So from the above > example I would be creating 3 datasets (csvs), of which the first one would > be > X Y1 Y2 1 4 20 1 0 > 52 1 20 15 1 17 > 18 > Appreciate any help. > > Thanks > Anamika > > [[alternative HTML version deleted]] > > ______________________________________________ > 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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] ______________________________________________ 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.