An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130611/1d42259d/attachment.pl>
extract common rows from a dataframe
3 messages · Ellie Papazisi, Bert Gunter, arun
1. What does "common" mean? (noting that 39.35 != 39.33 ) 2. But: ?"[" ## or easier, but less flexible ?subset Also, spend some time with "An Introduction to R." Unless I misunderstand, this is very basic, and you need to first put in some time to learn R's basic procedures instead of posting here. Hint:
x <- data.frame(a = sample(1:3,10,rep=TRUE), b = sample(letters[1:10],10)) x[x$a == 3,]
Cheers, Bert
On Tue, Jun 11, 2013 at 8:45 AM, Ellie Papazisi <elliepapazisi at gmail.com> wrote:
Hello, I'm trying to extract the common rows from a data frame, which is
something like this :
* DEPTH SALINITY DEPTH SALINITY*
*18 87 39.06 94 39.06*
*19 173 39.05 141 NA*
*20 260 39.00 188 39.07*
*21 312 38.97 207 39.03*
*22 1 39.36 1 39.35*
*23 10 39.36 10 39.33*
*24 20 39.36 20 39.33*
*25 30 39.35 30 39.33*
*
*
i want to extract the rows with the same depth.
i cannot do something like *data.frame[22:25,]* because i have lots of rows
any help?
thank you
[[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.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Hi, Try this: dat1<- read.table(text=" DEPTH SALINITY DEPTH SALINITY 18??? 87??? 39.06??? 94??? 39.06 19? 173??? 39.05? 141????? NA 20? 260??? 39.00? 188??? 39.07 21? 312??? 38.97? 207??? 39.03 22??? 1??? 39.36??? 1??? 39.35 23??? 10??? 39.36??? 10??? 39.33 24??? 20??? 39.36??? 20??? 39.33 25??? 30??? 39.35??? 30??? 39.33 ",sep="",header=TRUE) library(matrixStats) res<-dat1[rowDiffs(as.matrix(dat1[,c(1,3)]))==0,] res #?? DEPTH SALINITY DEPTH.1 SALINITY.1 #22???? 1??? 39.36?????? 1????? 39.35 #23??? 10??? 39.36????? 10????? 39.33 #24??? 20??? 39.36????? 20????? 39.33 #25??? 30??? 39.35????? 30????? 39.33 #or dat1[apply(dat1,1,function(x) x[1]-x[3]==0),] #?? DEPTH SALINITY DEPTH.1 SALINITY.1 #22???? 1??? 39.36?????? 1????? 39.35 #23??? 10??? 39.36????? 10????? 39.33 #24??? 20??? 39.36????? 20????? 39.33 #25??? 30??? 39.35????? 30????? 39.33 A.K. ----- Original Message ----- From: Ellie Papazisi <elliepapazisi at gmail.com> To: r-help at r-project.org Cc: Sent: Tuesday, June 11, 2013 11:45 AM Subject: [R] extract common rows from a dataframe Hello, I'm trying to extract the common rows from a data frame, which is something like this : *? DEPTH SALINITY DEPTH SALINITY* *18? ? 87? ? 39.06? ? 94? ? 39.06* *19? 173? ? 39.05? 141? ? ? NA* *20? 260? ? 39.00? 188? ? 39.07* *21? 312? ? 38.97? 207? ? 39.03* *22? ? 1? ? 39.36? ? 1? ? 39.35* *23? ? 10? ? 39.36? ? 10? ? 39.33* *24? ? 20? ? 39.36? ? 20? ? 39.33* *25? ? 30? ? 39.35? ? 30? ? 39.33* * * i want to extract the rows with the same depth. i cannot do something like *data.frame[22:25,]* because i have lots of rows any help? thank you ??? [[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.