[R] list matching

jim holtman jholtman at gmail.com
Mon Jun 14 15:30:55 CEST 2010


One thing you might do is to transform the data into a format that is
easier to combine; I like using 'merge':

> mynames=cbind(c('a','b'),c(11,22))
> lst=list(a=c(1,2), b=5)
> mynames
     [,1] [,2]
[1,] "a"  "11"
[2,] "b"  "22"
> lst
$a
[1] 1 2

$b
[1] 5

> mynames.df <- as.data.frame(mynames)
> mynames.df
  V1 V2
1  a 11
2  b 22
> lst.s <- stack(lst)
> lst.s
  values ind
1      1   a
2      2   a
3      5   b
> merge(mynames.df, lst.s, by.x="V1", by.y="ind")
  V1 V2 values
1  a 11      1
2  a 11      2
3  b 22      5
>


On Mon, Jun 14, 2010 at 8:06 AM, Yuan Jian <jayuan2008 at yahoo.com> wrote:
> Hello,
>
> I could not find a clear solution for the follow question. please allow me to ask. thanks
>
> mynames=cbind(c('a','b'),c(11,22))
> lst=list(a=c(1,2), b=5)
>
> now I try to combine mynames and lst:
> a  1  11
> a  2  11
> b  5  22
>
> thanks
> jian
>
>
>
>
>        [[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.
>
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list