[R] Odp: matching lists

Petr PIKAL petr.pikal at precheza.cz
Tue Apr 14 14:30:16 CEST 2009


Hi

lapply should do it if values is a data frame with first column of names 
and second column numbers.

lapply(v, function(x) values[match(x, values[ ,1]), 2])

Regards
Petr


r-help-bounces at r-project.org napsal dne 14.04.2009 14:01:50:

> Dear All,
>  
> Here's my problem. I have two lists:
>  
> > v
> [[1]]
> [1] "five"
> [[2]]
> [1] "four"
> [[3]]
> [1] "three"
> [[4]]
> [1] "two"
> [[5]]
> [1] "one"
> [[6]]
> [1] "six"
> [[7]]
> [1] "five"  "four"  "three" "two"   "one"   "six"  
> [[8]]
> [1] "four"  "three" "two"   "one"   "six"  
> [[9]]
> [1] "three" "two"   "one"   "six"  
> [[10]]
> [1] "two" "one" "six"
> 
>  
> and the other is something like:
>  
> >values
>       numbers
> five       50
> four       40
> three      30
> two        10
> one        10
> six        10
> > 
> 
> 
> 
> I'm trying to get a list similar to "v", but in which the entries 
"three", 
> "two", and so on are replaced by the values in the second list. Any help 
will 
> be greatly appreciated.
> 
> best regards,
> 
> Manoel
> 
> 
> 
>    [[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.




More information about the R-help mailing list