similar to: lapply returns NULL ?

Displaying 20 results from an estimated 200000 matches similar to: "lapply returns NULL ?"

2008 Sep 04
1
lapply(NULL, ...) returns empty list
Dear R-devel, Is there a reason that lapply(NULL, ...) returns the empty list, rather than NULL? It seems intuitive to expect the latter, and rather counterintuitive that lapply(list(), ... ) returns the same value as lapply(NULL, ...). > lapply(list(), function(x) 1) list() > lapply(NULL, function(x) 1) list() > version _ platform i386-pc-mingw32 arch
2017 Jun 15
0
is.null(mylist[1]) and is.null(mylist$a) returns different values
Thank you all , very informative, never thought of doing a str( mylist[1] ) -----Original Message----- From: "Jeff Newmiller" [jdnewmil at dcn.davis.ca.us] Date: 06/15/2017 11:56 AM To: r-help at r-project.org, "Huzefa Khalil" <huzefa.khalil at umich.edu>, "ce" <zadig_1 at excite.com> Subject: Re: [R] is.null(mylist[1]) and is.null(mylist$a) returns
2017 Jun 15
0
is.null(mylist[1]) and is.null(mylist$a) returns different values
Hi, Try > is.null(mylist[[1]]) [1] TRUE Notice the double square brackets. From: ?`[` "The most important distinction between [, [[ and $ is that the [ can select more than one element whereas the other two select a single element." On Thu, Jun 15, 2017 at 11:33 AM, ce <zadig_1 at excite.com> wrote: > Hi > > I have a list : > > mylist <- list( a = NULL, b
2017 Jun 15
4
is.null(mylist[1]) and is.null(mylist$a) returns different values
Hi I have a list : mylist <- list( a = NULL, b = 1, c = 2 ) > mylist[1] $a NULL > is.null(mylist[1]) [1] FALSE > is.null(mylist$a) [1] TRUE why? I need to use mylist[1]
2017 Jun 15
1
is.null(mylist[1]) and is.null(mylist$a) returns different values
I find that the str function is more helpful for understanding the difference between a null list and a list containing a null list than the implicit print function call that the interpreter invokes when you enter an expression at the console. str( mylist[1] ) -- Sent from my phone. Please excuse my brevity. On June 15, 2017 8:39:47 AM PDT, Huzefa Khalil <huzefa.khalil at umich.edu>
2006 Nov 07
1
Gregexpr - extract results with lapply
Gregexpr - extract results with lapply Hello, I need to extract sequences of three upper case letters in a string. In other words, in this string: str <-c("ABC", "this WOUld be gOOD") The result I'm looking for is ABC WOU OOD. With gregexpr, I can get the position and length of the sequences gregexpr('[A-Z]{3}',str,perl=TRUE) [[1]] [1] 1
2008 Oct 27
1
create list of data frames
Hi all, I need to realize nonlinear regression on a thousand data sets. I guess the lapply function would help me on that thus I'd like to create a list of data frames, each data frame containing the data as follows: Ce Qe 1 1.849147 0.1958672 2 10.054250 0.5771036 3 18.077246 0.7718514 4 27.576468 0.8079606 5 35.146862 0.8500489 6 43.245078 0.8366673 7 51.745760 0.8879672
2005 Jul 22
1
sapply(NULL, ...) returns a list?!?
Hi, I bet this one has be asked before, but doing sapply(x, FUN=as.character) where 'x' is a vector, then the result "should [] be simplified to a vector" according to ?sapply, correct? However, > x <- 1:10 > sapply(x, FUN=as.character) [1] "1" "2" "3" "4" "5" "6" "7" "8"
2007 Jul 30
2
apply, lapply and data.frame in R 2.5
Hello everyone, A recent (in 2.5 I suspect) change in R is giving me trouble. I want to apply a function (tolower) to all the columns of a data.frame and get a data.frame in return. Currently, on a data.frame, both apply (for arrays) and lapply (for lists) work, but each returns its native class (resp. matrix and list): apply(mydat,2,tolower) # gives a matrix lapply(mydat,tolower) # gives
2019 Oct 30
0
head.matrix can return 1000s of columns -- limit to n or add new argument?
>>>>> Gabriel Becker >>>>> on Tue, 29 Oct 2019 12:43:15 -0700 writes: > Hi all, > So I've started working on this and I ran into something that I didn't > know, namely that for x a multi-dimensional (2+) array, head(x) and tail(x) > ignore dimension completely, treat x as an atomic vector, and return an > (unclassed)
2007 May 18
3
lapply not reading arguments from the correct environment
Hello, I am facing a problem with lapply which I ''''think''' may be a bug. This is the most basic function in which I can reproduce it: myfun <- function() { foo = data.frame(1:10,10:1) foos = list(foo) fooCollumn=2 cFoo = lapply(foos,subset,select=fooCollumn) return(cFoo) } I am building a list of dataframes, in each of which I want to keep only column
2011 Oct 22
1
lapply to return vector
Dear all I have wrote the following line return(as.vector(lapply(as.data.frame(data),min,simplify=TRUE))); I want the lapply to return a vector as it returns a list with elements as shown below List of 30001 $ V1 : num -131 $ V2 : num -131 $ V3 : num -137 $ V4 : num -129 $ V5 : num -130 as you can see I have already tried the simplify=TRUE and also the as.vector() but both
2019 Oct 31
2
head.matrix can return 1000s of columns -- limit to n or add new argument?
On 10/30/19 04:29, Martin Maechler wrote: >>>>>> Gabriel Becker >>>>>> on Tue, 29 Oct 2019 12:43:15 -0700 writes: > > > Hi all, > > So I've started working on this and I ran into something that I didn't > > know, namely that for x a multi-dimensional (2+) array, head(x) and tail(x) > > ignore dimension
2011 Mar 30
4
a for loop to lapply
Dear all, I am trying to learn lapply. I would like, as a test case, to try the lapply alternative for the Shadowlist<-array(data=NA,dim=c(dimx,dimy,dimmaps)) for (i in c(1:dimx)){ Shadowlist[,,i]<-i } ---so I wrote the following--- returni <-function(i,ShadowMatrix) {ShadowMatrix<-i} lapply(seq(1:dimx),Shadowlist[,,seq(1:dimx)],returni) So far I do not get same results
2011 Apr 09
1
For->lapply->parallel apply
Dear all, I would like to ask your help understand the subsequent steps for making my program faster. The following code: Gauslist<-array(data=NA,dim=c(dimx,dimy,dimz)) for (i in c(1:dimz)){ print(sprintf('Creating the %d map',i)); Gauslist[,,i]<-f <- GaussRF(x=x, y=y, model=model, grid=TRUE,param=c(mean,variance,nugget,scale,Whit.alpha)) } creates 100 GaussMaps (each
2011 Sep 15
2
Returning the name of an object passed directly or from a list by lapply
Dear folks: Let?s suppose I want a function to print return the name of the object passed to it. > myname <- function(object) {out<-deparse(substitute(object)); out} This works fine on a single object: > O1 <-c(1:4) > myname(O1) [1] "O1" However it does not work if you use lapply to pass it the same object from a list: > O2 <-c(1:4) > object.list <-
2008 Feb 19
0
nlsList - Error in !unlist(lapply(coefs, is.null))
Howdee, I am able to fit a 4-parameter logistic growth curve to a dataset which comprise many individuals (using R v. 2.3.1). Yet, if I want to obtain the parameters for each individual (i.e., for each 'id') using nlsList, then I obtain an Error message which I have trouble interpreting. Any advice as to how I can solve this problem? Thanks for your time, Marc > reg <-nls(mass ~
2004 Oct 18
0
Increasing computiation time per column using lapply
Hi, Would be very glad for help on this problem. Using this code: temp<-function(x, bins, tot) { return(as.numeric(lapply(split(x, bins), wtest, tot))); } wtest <- function(x, y) { return(wilcox.test(x,y)$p.value); } rs <- function(x, bins) { binCount <- length(split(x[,1], bins)); tot <- as.numeric(x); result<-matrix(apply(x, 2, temp, bins, tot),
2012 Apr 24
1
returning functions inside lapply
This has been asked before, but I just cannot figure out why lapply should behave this way given that R uses lazy evalution. Even after reading (or at least trying to read) parts of the R language definition. > f <- function(x) {function() {x}} > a <- list(f(1), f(2), f(3)) > a[[1]]() # as expected [1] 1 > a[[2]]() # as expected [1] 2 > a[[3]]() # as expected [1] 3 > b
2004 May 20
2
for() to lapply()
Hi dear R-users: I have the following problem: I have a list of data.frames (12 variables and 60000 rows, each) I have to merge from an specific point of the list to the end of the list, I am doing so with a for() loop but it is too inefficient and it exhausts memory. How can I convert this for() loop in a function and then use lapply?