Displaying 20 results from an estimated 20000 matches similar to: "make methods work in lapply - remove lapply's environment"
2017 Mar 29
1
A trap for young players with the lapply() function.
(inline)
On Tue, 28 Mar 2017, Rolf Turner writes:
> On 28/03/17 04:21, Barry Rowlingson wrote:
>> On Mon, Mar 27, 2017 at 1:17 AM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
>>>
>>> Is there any way to trap/detect the use of an optional argument called
>>> "X" and thereby issue a more perspicuous error message?
>>>
>>>
2017 Mar 27
2
A trap for young players with the lapply() function.
On Mon, Mar 27, 2017 at 1:17 AM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
>
> Is there any way to trap/detect the use of an optional argument called
> "X" and thereby issue a more perspicuous error message?
>
> This would be helpful to those users who, like myself, are bears of very
> little brain.
>
> Failing that (it does look impossible)
You can
2020 Jun 26
1
Change in lapply's missing argument passing
Consider the following expression, in which we pass 'i=', with no value
given for the 'i' argument, to lapply.
lapply("x", function(i, j) c(i=missing(i),j=missing(j), i=)
>From R-2.14.0 (2011-10-31) through R-3.4.4 (2018-03-15) this evaluated to
c(i=TRUE, j=FALSE). From R-3.5.0 (2018-04-23) through R-4.0.0 (2020-04-24)
this evaluated to c(i=FALSE, j=TRUE).
Was
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
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,
...){
lapplyFunctionRecurse <- function(cdata, level=1,
2004 Aug 30
3
Multiple lapply get-around
I am faced with a situation wherein I have to use multiple lapply's. The
pseudo-code could be approximated to something as below:
For each X from i=1 to n
For each Y based on j=1 to m
For each F from 1 to f
Do some calculation based on Fij
Store Xi,Yj = Fij
End For F
End for Y
End for X
Is there anyway to optimize the processing logic further? I *guess*
using the multiple lapply
2015 Feb 26
3
iterated lapply
Would introducing the new frame, with the call to local(), cause problems
when you use frame counting instead of <<- to modify variables outside the
scope of lapply's FUN, I think the frame counts may have to change. E.g.,
here is code from actuar::simul() that might be affected:
x <- unlist(lapply(nodes[[i]], seq))
lapply(nodes[(i + 1):(nlevels - 1)],
2015 Feb 24
3
iterated lapply
From: Daniel Kaschek <daniel.kaschek at physik.uni-freiburg.de>
> ... When I evaluate this list of functions by
> another lapply/sapply, I get an unexpected result: all values coincide.
> However, when I uncomment the print(), it works as expected. Is this a
> bug or a feature?
>
> conditions <- 1:4
> test <- lapply(conditions, function(mycondition){
>
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
... but using an lapply "..."
2017 Nov 15
0
lapply and runif issue?
Hi Bert,
On Tue, Nov 14, 2017 at 8:11 PM, Bert Gunter <bgunter.4567 at 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)
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))
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 the original
2009 Aug 11
1
Passing a list object to lapply
Hello,
I'm having difficulty passing an object name to a lapply function. Can
somebody tell me the trick to make this work?
#Works
T13702 <- TRACKDATA[["13702.xls"]][["data"]]
min(unlist(lapply(list(T13702), function(x) mdy.date(x[1, 2], x[1, 1],
x[1, 3]))))
16553
#Works
d<-2
assign(paste("T",substr(names(TRACKDATA)[d],1,(nchar(names(TRACKDATA)[d]
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 bei #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't always seem to "work" as suggested by
this code (at least to the
2009 Aug 17
1
how to pass more than one argument to the function called by lapply?
Dear R helpers:
I wonder how to pass more than one argument to the function called by
lapply.
For example,
#R code below ---------------------------
indf <- data.frame(id=I(c('a','b')),y=c(1,10))
#I want to add an addition argument cutoff into the function called by
lapply.
outside.fun <- function(indf, cutoff)
{
unlist(lapply(split(indf, indf[,'id']),
2012 Sep 11
1
lapply with different size lists?
Hello,
I have 2 functions (a and b)
a = function(n) { matrix (runif(n*2,0.0,1), n) }
>
>
> b = function (m, matrix) {
> n=nrow (matrix)
> p=ceiling (n/m)
> lapply (1:p, function (l,n,m) {
> inf = ((l-1)*m)+1
> if (l<p) sup=((l-1)*m)+m
> else sup=n
>
2010 Sep 21
2
lapply version with [ subseting - a suggestion
Dear R developers,
Reviewing my code, I have realized that about 80% of the time in the lapply I
need to access the names of the objects inside the loop.
In such cases I iterate over indexes or names:
lapply(names(x), ... [i]),
lapply(seq_along(x), ... x[[i]] ... names(x)[i] ), or
for(i in seq_along(x)) ...
which is rather inconvenient.
How about an argument to lapply which would specify the
2009 Dec 08
2
could not find function lapply<-
R-help,
I have a list whose elements are data frames.
I want to change the colnames attribute in each element of this list but an error message
comes up:
> lapply(LD_strataNew,function(x) dimnames(x)[[2]][-1]) <- as.roman(1:9)[-6]
Error in lapply(LD_strataNew, function(x) dimnames(x)[[2]][-1]) <- as.roman(1:9)[-6] :
could not find function "lapply<-"
>
2010 Oct 15
1
Downloading file with lapply
I'm still getting familiar with lapply
I have this date sequence
x <- seq(as.Date("01-Jan-2010",format="%d-%b-%Y"), Sys.Date(), by=1) #to
generate series of dates
I want to apply the function for all values of x . so I use lapply (Still a
newbie!)
I wrote this test function
pFun <- function (x) {
print(paste("This is: ",x,sep=""))
}
When I