[R] Equivalent of match for data.frame

Carlos J. Gil Bellosta cgb at datanalytics.com
Sat Jan 3 14:45:55 CET 2009


Hello,

Why not something like

lapply(mydf, function(x) match(myarg, x) )

?

Best regards,

Carlos J. Gil Bellosta
http://www.datanalytics.com


On Sat, 2009-01-03 at 07:24 -0500, Sébastien wrote:
> Dear R-users,
> 
> I am translating a S script into R and having some troubles with the 
> match function. This function appears to work with vector and data.frame 
> in S, but not in R, e.g.:
> a <- rep((1:4), each = 10)
> b <- rep((1:10), times = 4)
> mydf <- data.frame(a,b)
> myarg <- mydf[1,]
> match(myarg, mydf)
> 
> # S returns 1 but R returns NA NA
> 
> I guess one could use match(interaction(myarg), interaction(mydf)) to do 
> the job but I was just wondering if there was a more direct function.
> 
> Thanks,
> 
> Sebastien
> 
> ______________________________________________
> 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