Re: [R] A question on list and lapply

2012-12-17 Thread MacQueen, Don
If you don't need the "P" element in the output, then I think the answers you've already received are good. But if you do want to retain the "P" element, then I think it's better to simply add the missing elements back in after using lapply. The code will be easier to understand a year from now. H

Re: [R] A question on list and lapply

2012-12-14 Thread arun
uot;P") paste0("(",base,")") else tolower(base) } ) names(res1) #NULL  names(res2) #[1] "O" "P" "Q" A.K. ----- Original Message - From: William Dunlap To: arun ; Christofer Bogaso Cc: R help Sent: Friday, December 14, 2012 3:59 P

Re: [R] A question on list and lapply

2012-12-14 Thread William Dunlap
re wdunlap tibco.com > -Original Message- > From: arun [mailto:smartpink...@yahoo.com] > Sent: Friday, December 14, 2012 1:37 PM > To: William Dunlap > Cc: R help > Subject: Re: [R] A question on list and lapply > > HI, > > By applying: > bases > #$O

Re: [R] A question on list and lapply

2012-12-14 Thread William Dunlap
t; you could use this: > set.seed(51) > lapply(lapply(Dat,My_Function),function(x) > {if(names(Dat)[match.call()[[2]][[3]]]%in% > "P") NULL else x}) > A.K. > > > > > - Original Message - > From: Christofer Bogaso > To: r-help@r-project.org > Cc

Re: [R] A question on list and lapply

2012-12-14 Thread arun
Bogaso To: r-help@r-project.org Cc: Sent: Friday, December 14, 2012 1:58 PM Subject: [R] A question on list and lapply Dear all, let say I have following list: Dat <- vector("list", length = 26) names(Dat) <- LETTERS My_Function <- function(x) return(rnorm(5)) Dat1 <- lapply(Dat,

Re: [R] A question on list and lapply

2012-12-14 Thread Mark Lamias
How about Dat1 <- lapply(subset(Dat, Dat!="P"), My_Function) --Mark From: Christofer Bogaso To: r-help@r-project.org Sent: Friday, December 14, 2012 1:58 PM Subject: [R] A question on list and lapply Dear all, let say I have followi

Re: [R] A question on list and lapply

2012-12-14 Thread Sarah Goslee
What about: lapply(Dat[names(Dat) != "P"], My_Function) You could use %in% if you actually want to match a longer set of names. Sarah On Fri, Dec 14, 2012 at 1:58 PM, Christofer Bogaso wrote: > Dear all, let say I have following list: > > Dat <- vector("list", length = 26) > names(Dat) <- LETT

[R] A question on list and lapply

2012-12-14 Thread Christofer Bogaso
Dear all, let say I have following list: Dat <- vector("list", length = 26) names(Dat) <- LETTERS My_Function <- function(x) return(rnorm(5)) Dat1 <- lapply(Dat, My_Function) However I want to apply my function 'My_Function' for all elements of 'Dat' except the elements having 'names(Dat) == "

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

[R] a question on list manipulation

2011-08-05 Thread zhenjiang xu
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 elements under each list name. Is there any quic

Re: [R] A question on List

2009-08-21 Thread baptiste auguie
Try this, mat <- replicate(4, matrix(rnorm(25), 5), simpl=F) mat vect <- rnorm(4) mapply( `*` , mat, vect, SIMPLIFY=F) HTH, baptiste PS: I see someone replied already, but you might find replicate useful too 2009/8/21 RON70 : > > Suppose I have following list : > > mat <- vector("list") > fo

[R] A question on List

2009-08-21 Thread RON70
Suppose I have following list : mat <- vector("list") for (i in 1:4) mat[[i]] <- matrix(rnorm(25),5) mat > mat [[1]] [,1] [,2] [,3] [,4] [,5] [1,] -1.27171814 -0.8087277 -0.4771356 0.6001265 0.9842248 [2,] -1.37337445 1.0754536 -1.6304287 -0.6854075 -0.6029