Re: [R] a question on list manipulation

2011-08-08 Thread Brian Diggs
your list elements end with digits that you don't want stripped off (but you can work around that by preprocessing the list names). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun..

Re: [R] a question on list manipulation

2011-08-06 Thread zhenjiang xu
gt; > > Of course this version will have some problems if the names of your list > elements end with digits that you don't want stripped off (but you can work > around that by preprocessing the list names). > > -- > Gregory (Greg) L. Snow Ph.D. > Statistical Data Cent

Re: [R] a question on list manipulation

2011-08-06 Thread zhenjiang xu
This is a nice solution. Thanks, Dennis. But I am afraid if the length of the list x isn't equal to the length of x2, there will be errors since lapply returns a list of the same length. > x <- list(A=c("d", "e", "f"), B=c("d", "e"), C=c("d","g")) > x2 <- unique(unlist(x)) > w <- lapply(x, functio

Re: [R] a question on list manipulation

2011-08-05 Thread Greg Snow
ripped off (but you can work around that by preprocessing the list names). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > pro

Re: [R] a question on list manipulation

2011-08-05 Thread Dennis Murphy
Hi: Your clarification suggests Duncan was on the right track, so how about this: x <- list(A=c("d", "e", "f"), B=c("d", "e"), C=c("d")) x2 <- unique(unlist(x)) w <- lapply(x, function(u) names(x)[which(x2 %in% u)]) names(w) <- x2 w $d [1] "A" "B" "C" $e [1] "A" "B" $f [1] "A" HTH, Dennis On

Re: [R] a question on list manipulation

2011-08-05 Thread zhenjiang xu
Exactly! Sorry I get others misunderstood. The uppercase/lowercase is only a toy example (and a bad one; yours is better than mine). My question is a more general one: a list is basically a one-to-many matching, from the names of a list to the elements belonging to each name. I'd like to reverse th

Re: [R] a question on list manipulation

2011-08-05 Thread Duncan Murdoch
On 05/08/2011 12:05 PM, zhenjiang xu wrote: Hi R users, I have a list: > x $A [1] "a" "b" "c" $B [1] "b" "c" $C [1] "c" I want to convert it to a lowercase-to-uppercase list like this: > y $a [1] "A" $b [1] "A" "B" $c [1] "A" "B" "C" In a word, I want to reverse the list names and the

Re: [R] a question on list manipulation

2011-08-05 Thread Jannis
toupper()/tolower() are the functions to convert the letters. lapply() can be used to apply this to different list elements and names() is helpfull to convert the names of your list. HTH Jannis On 08/05/2011 06:05 PM, zhenjiang xu wrote: Hi R users, I have a list: x $A [1] "a" "b" "

Re: [R] a question on list manipulation

2011-08-05 Thread David Winsemius
On Aug 5, 2011, at 12:05 PM, zhenjiang xu wrote: Hi R users, I have a list: x $A [1] "a" "b" "c" $B [1] "b" "c" $C [1] "c" I want to convert it to a lowercase-to-uppercase list like this: y $a [1] "A" $b [1] "A" "B" $c [1] "A" "B" "C" In a word, I want to reverse the list names and

Re: [R] a question on list manipulation

2011-08-05 Thread R. Michael Weylandt
There are a few moving pieces to do this: 1) the toupper and tolower functions. These can do almost everything you need: x = lapply(x,toupper) ## This changes the things inside x but won't change the names 2) Now, there are two ways to think about getting the elements from one list to another: I