Re: [R] access elements of a named list using a factor

2009-10-24 Thread Uwe Ligges
Robin, see below my inserted comments. Robin Hankin wrote: Hello Dimitris thanks for this. It works! I guess I was fixated on the dollar sign. I must confess that I don't really understand any of the error messages below. Can anyone help me interpret them? rksh Dimitris Rizopoulos wr

Re: [R] access elements of a named list using a factor

2009-10-23 Thread Robin Hankin
Hello Dimitris thanks for this. It works! I guess I was fixated on the dollar sign. I must confess that I don't really understand any of the error messages below. Can anyone help me interpret them? rksh Dimitris Rizopoulos wrote: do you mean: f <- factor(c("pigs", "pigs", "slugs")) jj

Re: [R] access elements of a named list using a factor

2009-10-23 Thread Dimitris Rizopoulos
do you mean: f <- factor(c("pigs", "pigs", "slugs")) jj <- list(pigs = 1:10, slugs = 1:3) jj[levels(f)[1]] jj[[levels(f)[1]]] Best, Dimitris Robin Hankin wrote: Hi I have a factor 'f' and a named list 'jj'. I want names(jj) to match up with levels(f). How do I use levels(f) to access ele

[R] access elements of a named list using a factor

2009-10-23 Thread Robin Hankin
Hi I have a factor 'f' and a named list 'jj'. I want names(jj) to match up with levels(f). How do I use levels(f) to access elements of jj? > f <- factor(c("pigs","pigs","slugs")) > f [1] pigs pigs slugs Levels: pigs slugs > > jj <- list(pigs=1:10,slugs=1:3) My attempts to produce jj$pig