Mark Na
2009-Jun-16 17:41 UTC
[R] How to extract all rows that contain the value of X in any column?
Hi R-helpers, I'm trying to use this code> pvh_dnv<-pvh[sapply(pvh=="dnv"),]to make a new dataframe containing the rows from pvh that contain the value of "dnv" in ANY column. But, it's not working. I get this error Error in match.fun(FUN) : element 1 is empty; the part of the args list of 'is.function' being evaluated was: (FUN) which, to me, is cryptic. I'd appreciate any help you might provide, thanks! Mark Na
David Winsemius
2009-Jun-16 17:52 UTC
[R] How to extract all rows that contain the value of X in any column?
No example. You are a regular now and examples ARE requested. Would have thought something along the lines of: pvh[ unlist( apply(pvh, 1, function(x) "dnv" %in% as.character(x) ) ) , ] Not sure if the unlist or as.character are really needed because ... no example on which to test. On Jun 16, 2009, at 1:41 PM, Mark Na wrote:> Hi R-helpers, > > I'm trying to use this code > >> pvh_dnv<-pvh[sapply(pvh=="dnv"),] > > to make a new dataframe containing the rows from pvh that contain the > value of "dnv" in ANY column. > > But, it's not working. I get this error > > Error in match.fun(FUN) : element 1 is empty; > the part of the args list of 'is.function' being evaluated was: > (FUN) > > which, to me, is cryptic. > > I'd appreciate any help you might provide, thanks! > > Mark Na > > ______________________________________________ > 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.David Winsemius, MD Heritage Laboratories West Hartford, CT
Henrique Dallazuanna
2009-Jun-16 18:09 UTC
[R] How to extract all rows that contain the value of X in any column?
Try this: pvh[apply(pvh == "dnv", 2, any)] On Tue, Jun 16, 2009 at 2:41 PM, Mark Na <mtb954@gmail.com> wrote:> Hi R-helpers, > > I'm trying to use this code > > > pvh_dnv<-pvh[sapply(pvh=="dnv"),] > > to make a new dataframe containing the rows from pvh that contain the > value of "dnv" in ANY column. > > But, it's not working. I get this error > > Error in match.fun(FUN) : element 1 is empty; > the part of the args list of 'is.function' being evaluated was: > (FUN) > > which, to me, is cryptic. > > I'd appreciate any help you might provide, thanks! > > Mark Na > > ______________________________________________ > 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]]
Jorge Ivan Velez
2009-Jun-16 18:12 UTC
[R] How to extract all rows that contain the value of X in any column?
Dear Mark, If I understood correctly, the following should work: index <- apply(pvh, 1, function(x) any(x == "dnv") ) pvh_dnv <- pvh[index,] pvh_dnv HTH, Jorge On Tue, Jun 16, 2009 at 1:41 PM, Mark Na <mtb954@gmail.com> wrote:> Hi R-helpers, > > I'm trying to use this code > > > pvh_dnv<-pvh[sapply(pvh=="dnv"),] > > to make a new dataframe containing the rows from pvh that contain the > value of "dnv" in ANY column. > > But, it's not working. I get this error > > Error in match.fun(FUN) : element 1 is empty; > the part of the args list of 'is.function' being evaluated was: > (FUN) > > which, to me, is cryptic. > > I'd appreciate any help you might provide, thanks! > > Mark Na > > ______________________________________________ > 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]]