[R] How to manipulate this data?
Hi, I want my output to be like this: Value BXR abc DHH abc DHK abc def DSL def ghi DSM abc def ghi DSS def ghi DST ghi DIW abc DIL abc ghi My input dataset is this with colnames name and Value: name Value abc BXR abc DHH abc DHK def DHK def DSL ghi DSL abc DSM def DSM ghi DSM def DSS ghi DSS ghi DST abc DIW abc DIL ghi DIL [[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.
Re: [R] How to manipulate this data?
Hi, Try: dat1- read.table(text=name Value abc BXR abc DHH abc DHK def DHK def DSL ghi DSL abc DSM def DSM ghi DSM def DSS ghi DSS ghi DST abc DIW abc DIL ghi DIL,sep=,header=TRUE,stringsAsFactors=FALSE) aggregate(name~Value,data=dat1,paste,collapse= ) #or library(plyr) ddply(dat1,.(Value),summarize, name=lapply(list(Value),paste,collapse= )) A.K. Hi, I want my output to be like this: Value BXR abc DHH abc DHK abc def DSL def ghi DSM abc def ghi DSS def ghi DST ghi DIW abc DIL abc ghi My input dataset is this with colnames name and Value: name Value abc BXR abc DHH abc DHK def DHK def DSL ghi DSL abc DSM def DSM ghi DSM def DSS ghi DSS ghi DST abc DIW abc DIL ghi DIL __ 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.
[R] how to manipulate this data? Thank you very much!
Hi, R experts: I am asking for helps with manipulating this data: we have different groups: A,B, C, and so on. In each group, we have different students, for example, we have 6 students in A and 5 students in B. Each student gives a rating, which ranges from 1 to 3. We want to manipulate this data and add three more variables called as 1, as 2 and as 3. For example, in group A, for each student, we count the # of student before this student provides rating as 1, rating as 2 and rating as 3. For example, for student 2 in group A, there are 0 students before him/her provide rating as 1, there are 0 students before him/her provide rating as 2, there are 1 students before him/her provide rating as 3. For student 3 in group A, there are 0 students before him/her provide rating as 1, there are 1 students before him/her provide rating as 2, there are 1 students before him/her provide rating as 3. group student rating as 1 as 2 as 3 A 1 3 -- -- -- A 2 2 0 01 A 3 2 0 11 A 4 3 0 21 A 5 1 0 22 A 6 2 1 22 A 7 3 1 32 B 1 2 -- -- -- B 2 3 0 10 B 3 3 0 11 B 4 1 0 12 B 5 1 1 12 Best Jay [[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.
Re: [R] how to manipulate this data? Thank you very much!
try this: x - read.table(textConnection(group student rating + A 1 3 + A 2 2 + A 3 2 + A 4 3 + A 5 1 + A 6 2 + A 7 3 + B 1 2 + B 2 3 + B 3 3 + B 4 1 + B 5 1 ), header=TRUE, as.is=TRUE) # add the columns for the ratings ratings - sort(unique(x$rating)) # get the different ratings for (i in ratings){ + x[[paste('as', i)]] - ave(x$rating, x$group, FUN=function(a){ + c(NA, head(cumsum(a == i), -1)) + }) + } x group student rating as 1 as 2 as 3 1 A 1 3 NA NA NA 2 A 2 2001 3 A 3 2011 4 A 4 3021 5 A 5 1022 6 A 6 2122 7 A 7 3132 8 B 1 2 NA NA NA 9 B 2 3010 10 B 3 3011 11 B 4 1012 12 B 5 1112 On Sat, Jan 16, 2010 at 11:38 PM, jie feng jiefeng...@gmail.com wrote: Hi, R experts: I am asking for helps with manipulating this data: we have different groups: A,B, C, and so on. In each group, we have different students, for example, we have 6 students in A and 5 students in B. Each student gives a rating, which ranges from 1 to 3. We want to manipulate this data and add three more variables called as 1, as 2 and as 3. For example, in group A, for each student, we count the # of student before this student provides rating as 1, rating as 2 and rating as 3. For example, for student 2 in group A, there are 0 students before him/her provide rating as 1, there are 0 students before him/her provide rating as 2, there are 1 students before him/her provide rating as 3. For student 3 in group A, there are 0 students before him/her provide rating as 1, there are 1 students before him/her provide rating as 2, there are 1 students before him/her provide rating as 3. group student rating as 1 as 2 as 3 A 1 3 -- -- -- A 2 2 0 01 A 3 2 0 11 A 4 3 0 21 A 5 1 0 22 A 6 2 1 22 A 7 3 1 32 B 1 2 -- -- -- B 2 3 0 10 B 3 3 0 11 B 4 1 0 12 B 5 1 1 12 Best Jay [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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.
[R] How to manipulate a data frame
Dear list, I have a data frame like: log2.ratios[1:3,1:4] Clone a1 a2 a3 1 GS1-232B23 -0.0207500 0.17553833 0.21939333 2 RP11-82D16 -0.1896667 0.02645167 -0.03112333 3 RP11-62M23 -0.1761700 0.08214500 -0.04877000 how to make it to look like: log2.ratios[1:3,1:4] a1 a2 a3 a4 GS1-232B23 -0.0207500 0.17553833 0.21939333 0.0008 RP11-82D16 -0.1896667 0.02645167 -0.03112333 0.007 RP11-62M23 -0.1761700 0.08214500 -0.048770000.7666 I tried as.matrix(log2.ratios) and it seems it is not working. Thanks a lot! Allen [[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.
Re: [R] How to manipulate a data frame
affy snp wrote: Dear list, I have a data frame like: log2.ratios[1:3,1:4] Clone a1 a2 a3 1 GS1-232B23 -0.0207500 0.17553833 0.21939333 2 RP11-82D16 -0.1896667 0.02645167 -0.03112333 3 RP11-62M23 -0.1761700 0.08214500 -0.04877000 how to make it to look like: log2.ratios[1:3,1:4] a1 a2 a3 a4 GS1-232B23 -0.0207500 0.17553833 0.21939333 0.0008 RP11-82D16 -0.1896667 0.02645167 -0.03112333 0.007 RP11-62M23 -0.1761700 0.08214500 -0.048770000.7666 log2.ratios = data.frame( Clone=c(GS1-232B23, RP11-82D16, RP11-62M23), a1= c(-0.0207500,-0.1896667,-0.1761700), a2 = c(0.17553833,0.02645167,0.08214500), a3 = c(0.21939333,-0.03112333,-0.04877000), a4 = c(0.0008,0.007,0.7666)) log2.ratios[1:3,1:4] rownames(log2.ratios) - as.character(log2.ratios[,1]) log2.ratios - log2.ratios[,-1] -- View this message in context: http://www.nabble.com/How-to-manipulate-a-data-frame-tf4898180.html#a14030339 Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] How to manipulate a data frame
Thanks a lot, Petr. Allen On Nov 29, 2007 12:12 PM, Petr PIKAL [EMAIL PROTECTED] wrote: Hi I just guess what you want but maybe rownames(log2.ratios) -log2ratios$Clone changes rownames and then you could get your output (after getting rid of first column). If you just want an output to spreadsheet without row names column, look at ?write.table especially row.names option. regards Petr [EMAIL PROTECTED] [EMAIL PROTECTED] napsal dne 29.11.2007 17:06:57: Dear list, I have a data frame like: log2.ratios[1:3,1:4] Clone a1 a2 a3 1 GS1-232B23 -0.0207500 0.17553833 0.21939333 2 RP11-82D16 -0.1896667 0.02645167 -0.03112333 3 RP11-62M23 -0.1761700 0.08214500 -0.04877000 how to make it to look like: log2.ratios[1:3,1:4] a1 a2 a3 a4 GS1-232B23 -0.0207500 0.17553833 0.21939333 0.0008 RP11-82D16 -0.1896667 0.02645167 -0.03112333 0.007 RP11-62M23 -0.1761700 0.08214500 -0.048770000.7666 I tried as.matrix(log2.ratios) and it seems it is not working. Thanks a lot! Allen [[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. [[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.