search for: lapply

Displaying 20 results from an estimated 4142 matches for "lapply".

Did you mean: apply
2006 Jun 14
4
a new way to crash R? (PR#8981)
...ftware! Now the bad news: The attached script (or the original version with real data) will reliably crash R on my machine. I am using: R version: either 2.2.1 or 2.3.1 Windows 2000 Professional, Service Pack 4 512 MB of RAM On my machine the script will crash R on line 42 [ probits21 <- lapply(... ]. In both this script and the "real" one, memory.size() indicates that R is about 512 MB just before executing the command that crashes it. In other contexts, R has been able to allocate virtual memory on this computer without any trouble. Thanks again for all your work on R...
2014 Jun 23
1
Curious behavior of $ and lapply
There seems to be a funny interaction between lapply and "$" -- also, "$" doesn't signal an error in some cases where "[[" does. The $ operator accepts a string second argument in functional form: > `$`(list(a=3,b=4),"b") [1] 4 lapply(list(list(a=3,b=4)),function(x) `$`(x,"b")) [[1]] [1] 4...
2013 Feb 28
11
new question
...t;/home/arunksa111/data.new" #first function filelist<-function(directory,number,list1){ setwd(directory) filelist1<-dir(directory) direct<-dir(directory,pattern = paste("MSMS_",number,"PepInfo.txt",sep=""), full.names = FALSE, recursive = TRUE) list1<-lapply(direct, function(x) read.table(x,header=TRUE, sep = "\t",stringsAsFactors=FALSE)) names(list1)<-filelist1 list2<- list(filelist1,list1) return(list2) } foldernames1<-filelist(directory,23,list1)[[1]] foldernames1 #[1] "a1" "c1" "c2" "c3" &q...
2008 Sep 09
2
make methods work in lapply - remove lapply's environment
I've defined my own version of summary.default, that gives a better summary for highly skewed vectors. If I call summary(x) the method is used. If I call summary(data.frame(x)) the method is not used. I've traced this to lapply; this uses the new method: lapply(list(x), function(x) summary(x)) and this does not: lapply(list(x), summary) If I make a copy of lapply, WITHOUT the environment, then the method is used. lapply <- function (X, FUN, ...) { FUN <- match.fun(FUN) if (!is.vector(X) || is.object(X)...
2013 Jun 08
0
data
...s of those rows and the first row dimension was minimum (after I applied the first #constraint).? I guess you wanted to select only a pair of rows (dummy=0 and dummy=1) for each lists. fun1<- function(dat,percent,number){??? ??? lst1<- split(dat,list(dat$year,dat$industry)) ??? lst1New<- lapply(lst1,function(x) x[!(all(x$dummy==0)|all(x$dummy==1)),]) ??? lst2<- lst1New[lapply(lst1New,nrow)>0] ??? lst3<- lapply(lst2,function(x){ ??? ??? ??? ??? lapply(x$dimension,function(y){ ??? ??? ??? ??? ? x1<- x[(y < (x$dimension+(x$dimension*percent))) & (y > (x$dimension-(x$dim...
2005 Oct 10
2
problem with lapply(x, subset, ...) and variable select argument
I need to extract identically named columns from several data frames in a list. the column name is a variable (i.e. not known in advance). the whole thing occurs within a function body. I'd like to use lapply with a variable 'select' argument. example: tt <- function (n) { x <- list(data.frame(a=1,b=2), data.frame(a=3,b=4)) for (xx in x) print(subset(xx, select = n)) ### works print (lapply(x, subset, select = a)) ### works print (lapply(x, subset, select = "a&q...
2013 Mar 13
2
holding argument(s) fixed within lapply
|Hello, Given a function with several arguments, I would like to perform an lapply (or equivalent) while holding one or more arguments fixed to some common value, and I would like to do it in as elegant a fashion as possible, without resorting to wrapping a separate wrapper for the function if possible. Moreover I would also like it to work in cases where one or more arguments to...
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),Shadowlis...
2009 Nov 19
5
Accessing list names in lapply
Hi, When using lapply (or sapply) to loop over a list, can I somehow access the index of the list from inside the function? A trivial example: df1 <- split( x=rnorm(n=100, sd=seq(from=1, to=10, each=10)), f=letters[seq(from=1, to=10, each=10)] ) str(df1) #List of 10 # $ a: num [1:10] -0.801 0.418 1.451 -0.55...
2017 Nov 15
3
lapply and runif issue?
Could someone please explain the following? I did check bug reports, but did not recognize the issue there. I am reluctant to call it a bug, as it is much more likely my misunderstanding. Ergo my request for clarification: ## As expected: > lapply(1:3, rnorm, n = 3) [[1]] [1] 2.481575 1.998182 1.312786 [[2]] [1] 2.858383 1.827863 1.699015 [[3]] [1] 1.821910 2.530091 3.995677 ## Unexpected by me: > lapply(1:3, runif, n = 3) [[1]] [1] 1 1 1 [[2]] [1] NaN NaN NaN [[3]] [1] NaN NaN NaN Warning messages: 1: In FUN(X[[i]], ...) : NAs pr...
2012 Dec 14
5
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, My_Function) However I want to apply my function 'My_Function' for all elements of 'Dat' except the elements having 'names(Dat) == "P"'. Here I have specified the name "P" just for illustration however this will be some name specified by user....
2004 Oct 06
3
lapply with argument "X"
Hi, I am probably making a simple mistake but I can't see it > X Error: Object "X" not found > exists("X") [1] FALSE > lapply("X", exists) [[1]] [1] TRUE Why is lapply producing true? Is it something to do with the first argument of lapply also being called 'X'? > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 stat...
2012 Dec 11
2
debug on lapply
Dear R experts, recently I tried to debug a R function with an internal lapply call. When debugging I seem not to be able to use the "n" command to debug the inner function called by lapply. How could I achieve this? *For example:* test <- function( ) { lapply( 1:3, function( x ) x + 1 ) } debug( test ) *Start debug:* > test() debugging in: test() debug be...
2004 Sep 28
5
Bug? using { as a function in lapply
This seems like a bug to me. Can someone verify this? First we define a function f that returns its second argument and lapply it to 1:2 using 9 as the second argument and all seems well. Note that "{" as a function does the same thing as f, as illustrated with f(1,9) and "{"(1,9); however, when we attempt to use "{" in the very same way we used f in lapply, we get an error message about .....
2017 Nov 15
0
lapply and runif issue?
...gmail.com> wrote: > Could someone please explain the following? I did check bug reports, but > did not recognize the issue there. I am reluctant to call it a bug, as it > is much more likely my misunderstanding. Ergo my request for clarification: > > ## As expected: > >> lapply(1:3, rnorm, n = 3) > [[1]] > [1] 2.481575 1.998182 1.312786 > > [[2]] > [1] 2.858383 1.827863 1.699015 > > [[3]] > [1] 1.821910 2.530091 3.995677 > Exactly what expectation do you imagine the above is consistent with? Does > lapply(100*(1:3), rnorm, n = 3) [[1]] [1]...
2008 Jan 31
2
Pb with lapply()
Hi, If needed, lapply() tries to convert its first argument into a list before it starts doing something with it: > lapply function (X, FUN, ...) { FUN <- match.fun(FUN) if (!is.vector(X) || is.object(X)) X <- as.list(X) .Internal(lapply(X, FUN)) } But in practice, things don'...
2019 Nov 27
2
error in parallel:::sendMaster
Hi, I am facing a very weird problem with parallel::mclapply. I have a script which does some data wrangling on an input dataset in parallel and then writes the results to disk. I have been using this script daily for more than one year always on an EC2 instance launched from the same AMI (no updates installed after launch) and processed thousands of differe...
2010 Feb 26
2
dramatic speed difference in lapply
So I have a function that does lapply's for me based on dimension. Currently only works for length(pivotColumns)=2 because I haven't fixed the rbinds. I have two versions. One runs WAYYY faster than the other. And I'm not sure why. Fast Version: fedb.ddplyWrapper2Fast <- function(data, pivotColumns, listNameFunctions,...
2012 Mar 09
1
extracting the i-th row of a matrix in a list of lists
Hi, what is the proper of of "passing a missing value" so I can extract the entire i-th row of a matrix (in a list of lists) without pre-computing the number of cols? For example, if I know that the matrices have 2 columns, I can do the following: set.seed(1) x0 <- lapply(1:10, function(i) replicate(4, list(matrix(rnorm(10), nc=2)))) lapply(lapply(x0, '[[', 3), '[', i=2, j=1:2) (given that if I don't specify j, I only get the first element) but if the number of columns are variable: x1 <- lapply(1:10, function(i) replicate(4, list(matrix(rn...
2004 Feb 11
6
lapply and dynamically linked functions
Hi all, I'm trying to use lapply on a list with the following command: out<-lapply(mylist,myfun,par1=p,par2=d) (1) where myfun<-function(x,par1,par1) {.....} (2) now this function is in fact a wrapper for some Fortran code I have written so I think this might be the problem. When I call la...