Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20100729/2fc86d3d/attachment.pl>
Here's one way, using a function from the plyr package: TheLittleOne<-data.frame(cbind(c(2,3),c(2,3))) TheBigOne<-data.frame(cbind(c(1,1,2),c(1,1,2))) keys <- plyr:::join.keys(TheBigOne, TheLittleOne) !(keys$x %in% keys$y) TheBigOne[!(keys$x %in% keys$y), ] Hadley On Thu, Jul 29, 2010 at 1:38 PM, BaKaLeGuM <bakalegum at gmail.com> wrote:> Hi everybody ! > > little question. > > I have 2 dataset > > TheLittleOne<-data.frame(cbind(c(2,3),c(2,3))) > TheBigOne<-data.frame(cbind(c(1,1,2),c(1,1,2))) > > And I would like to obtain the TheBigOne - TheLittleOne (the row in > TheBigOne not in TheLittleOne > > The result should be: > cbind(c(1,1),c(1,1)) > > > Have you any idea? > > > > > PS : this function work.. but too slow and too much complex!.. > > diff2data<-function(data1,data2){ > afaire<-setdiff(paste(data1[,1],data1[,2]),paste(data2[,1],data2[,2])) > afaire<-data.frame(t(data.frame(strsplit(afaire," ")))) > if (sum(dim(afaire)) > !=0){afaire[,1]<-as.numeric(as.character(afaire[,1]));afaire[,2]<-as.numeric(as.character(afaire[,2]))} > return(afaire)} > > ? ? ? ?[[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. >-- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
Well, here's one way that "might" work (explanation below): The ideas is to turn each row into a character vector and then work with the two character vectors.> bigs <- do.call(paste,TheBigOne) > ix <- which(bigs %in% setdiff(bigs,do.call(paste,TheLittleOne))) > TheBigOne[ix,]However, this may not work if the data frame contain calculated numeric values which theoretically (infinite precision) are equal but are not exactly due to finite precision. For example, try:> 0 %in% pi/2If this is what you have, then you have to do something fancier working directly with the numeric values. Bert Gunter Genentech Nonclinical Biostatistics On Thu, Jul 29, 2010 at 11:38 AM, BaKaLeGuM <bakalegum@gmail.com> wrote:> Hi everybody ! > > little question. > > I have 2 dataset > > TheLittleOne<-data.frame(cbind(c(2,3),c(2,3))) > TheBigOne<-data.frame(cbind(c(1,1,2),c(1,1,2))) > > And I would like to obtain the TheBigOne - TheLittleOne (the row in > TheBigOne not in TheLittleOne > > The result should be: > cbind(c(1,1),c(1,1)) > > > Have you any idea? > > > > > PS : this function work.. but too slow and too much complex!.. > > diff2data<-function(data1,data2){ > afaire<-setdiff(paste(data1[,1],data1[,2]),paste(data2[,1],data2[,2])) > afaire<-data.frame(t(data.frame(strsplit(afaire," ")))) > if (sum(dim(afaire)) > > !=0){afaire[,1]<-as.numeric(as.character(afaire[,1]));afaire[,2]<-as.numeric(as.character(afaire[,2]))} > return(afaire)} > > [[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]]
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20100729/7ea2b19a/attachment.pl>
Try this also: TheBigOne[rowSums(!mapply(is.element, TheBigOne, TheLittleOne)) > 0,] On Thu, Jul 29, 2010 at 3:38 PM, BaKaLeGuM <bakalegum@gmail.com> wrote:> Hi everybody ! > > little question. > > I have 2 dataset > > TheLittleOne<-data.frame(cbind(c(2,3),c(2,3))) > TheBigOne<-data.frame(cbind(c(1,1,2),c(1,1,2))) > > And I would like to obtain the TheBigOne - TheLittleOne (the row in > TheBigOne not in TheLittleOne > > The result should be: > cbind(c(1,1),c(1,1)) > > > Have you any idea? > > > > > PS : this function work.. but too slow and too much complex!.. > > diff2data<-function(data1,data2){ > afaire<-setdiff(paste(data1[,1],data1[,2]),paste(data2[,1],data2[,2])) > afaire<-data.frame(t(data.frame(strsplit(afaire," ")))) > if (sum(dim(afaire)) > > !=0){afaire[,1]<-as.numeric(as.character(afaire[,1]));afaire[,2]<-as.numeric(as.character(afaire[,2]))} > return(afaire)} > > [[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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]