[R] Data Manipulation in R
arun
smartpink111 at yahoo.com
Mon Oct 21 07:11:58 CEST 2013
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 <canamika at 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 at 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.
More information about the R-help
mailing list