Displaying 20 results from an estimated 50000 matches similar to: "Problem with {"
2006 Sep 03
3
Merge list to list - as list
Dear all,
#Last week, I asked about merge x and y as list.
#Now I have a dataset with list of list like:
x <- list(list(matrix(1:20, 5, 4),matrix(1:20, 5, 4)),
list(matrix(1:20, 5, 4),matrix(1:20, 5, 4)))
y <- list(list(c(1, -1, -1, 1, 1),c(1, 1, -1, -1, -1)),
list(c(1, 1, 1, 1, 1),c(1, 1, -1, 1, -1)))
x
y
#I need merge x and y, I have tried with
list.uni <-
2006 Nov 17
1
which operators are available? (was: Re: do.call("+", ...))
I did not realize that ++ was available. Is there a comprehensive list
somewhere of which operators are available for definition? I searched
the R Language manual for ++ but that only came up with a reference to C++ .
On 17 Nov 2006 11:38:43 +0100, Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote:
> rfrancois at mango-solutions.com writes:
>
> > Hi,
> >
> > You
2003 Oct 16
2
returning dynamic variable names from function
Within a function I'm assigning dynamic variable names and values to them
using the "assign" function. I want to pass back the results but am
uncertain how to do this.
Basically, my function reads a number of data files and uses the filename of
each file as the variable name for a list-to-become-dataframe. I want then
to pass all these lists back, but again, the names of the
2011 Mar 25
2
Preserving the class of POSIXt objects
Dear all,
I am working with a list of objects each of which contains two POSIXct
objects (say, $Start and $End) and a number of different data in
addition to that. Now an easy way to extract Start times of all object
could be sapply(x, "[", "Start") but this converts them all to
numeric, and so does sapply(x, "[[", "Start"). lapply preserves the
class but
2020 Apr 20
1
suggestion: "." in [lsv]apply()
Le 19/04/2020 ? 20:46, Gabor Grothendieck a ?crit?:
> You can get pretty close to that already using fn$ in the gsubfn package:
>> library(gsubfn) fn$sapply(split(mtcars, mtcars$cyl), x ~
>> summary(lm(mpg ~ wt, x))$r.squared)
> 4 6 8 0.5086326 0.4645102 0.4229655
Right, I thought about similar syntax but this implementation has
similar flaws pointed by Simon, i.e. it reduces
2020 Feb 26
1
Profiling: attributing costs to place of invocation (instead of place of evaluation)?
Hi
Consider the following example:
f <- function(expr) g(expr)
g <- function(expr) {
? h(expr)
}
h <- function(expr) {
? expr # evaluation happens here
? i(expr)
}
i <- function(expr) {
? expr # already evaluated, no costs here
? invisible()
}
rprof <- tempfile()
Rprof(rprof)
f(replicate(1e2, sample.int(1e4)))
Rprof(NULL)
cat(readLines(rprof), sep = "\n")
#>
2015 Feb 26
1
iterated lapply
> On Feb 25, 2015, at 5:35 PM, Benjamin Tyner <btyner at gmail.com> wrote:
>
> Actually, it depends on the number of cores:
Under current semantics, yes. Each 'stream' of function calls is lazily capturing the last value of `i` on that core.
Under Luke's proposed semantics (IIUC),
the result would be the same (2,4,6,8) for both parallel and serial execution. This is
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"
2010 Jan 26
1
splitting a factor column into binary columns for each factor
Yesterday I posted the following question (my apologies for not putting a subject line):
=================question======================
Hello -- I would like to know of a more efficient way of writing the following piece of code. Thanks.
options(stringsAsFactors=FALSE)
orig <- c(rep('11111111',100000),rep('22222222',200000),rep('33333333'
2015 Feb 24
2
iterated lapply
> On Feb 24, 2015, at 10:50 AM, <luke-tierney at uiowa.edu> wrote:
>
> The documentation is not specific enough on the indented semantics in
> this situation to consider this a bug. The original R-level
> implementation of lapply was
>
> lapply <- function(X, FUN, ...) {
> FUN <- match.fun(FUN)
> if (!is.list(X))
> X <-
2009 Apr 27
3
Formatting numbers
I've been trough the R documentation for about half an hour and it's not
clear to me how to do this:
I need to format to character a series of integers from 1 to 1000, and I
like them to look like
"0001" "0002", "0059", "0123" and so on. Padded with zeroes to have four
digits.
Cheers!
Mario.
r-help-request at r-project.org wrote:
> Send
2008 Aug 02
2
lapply, sapply
Hello everybody,
I have problem with a lapply command, which rather proves that I don't
fully understand it.
I want to extract from a list that consists of dataframes, the length
of the first sequences from a given variable (its part of a simulation
exercises).
Below is code which does the job, but I think it should be possible to
make it more compact.
### Example Data
dat <-list()
2007 Mar 23
1
objects of class "matrix" and mode "list"?
Hello everyone,
I cannot seem to find information about objects of class "matrix" and mode
"list", and how to handle them (apart from flattening the list). I get this
type of object from using sapply(). Sorry for the long example, but the code
below illustrates how I get this type of object. Is anyone aware of
documentation regarding this object?
Thanks very much,
Stephen
2005 Nov 08
5
Using split and sapply to return entire lines
Hello,
I have a data manipulation problem that I can easily resolve by using
perl or python to pre-process the data, but I would prefer to do it
directly in R.
Given, for example:
month length ratio monthly1 monthly2
1 Jan 23 0.1 9 6
2 Jan 45 0.2 9 6
3 Jan 16 0.3 9 6
4 Feb 14 0.2 1 9
5 Mar 98 0.4 2 2
6 Mar 02 0.6
2005 Jan 08
2
Does R accumulate memory
Dear List:
I am running into a memory issue that I haven't noticed before. I am
running a simulation with all of the code used below. I have increased
my memory to 712mb and have a total of 1 gb on my machine.
What appears to be happening is I run a simulation where I create 1,000
datasets with a sample size of 100. I then run each dataset through a
gls and obtain some estimates.
This works
2008 Jul 21
1
confusion about evaluation.
Hi All, I am confused about the following code. I thought that the
problem stemmed from lazy evaluation and the fact that 'i' is never
evaluated within the first lapply. However, I am then confused as to
why it gets bound to the final element of the lapply. The environments
of the returned functions are indeed different in both cases and each
environment has a local binding for
2015 Feb 23
5
iterated lapply
Hi everybody,
with the following code I generate a list of functions. Each function
reflects a "condition". 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){
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){
>
2009 Aug 11
3
Is there a summary on different version of 'apply' functions? What is the meaning of the prefixes?
Hi,
There are quiet a few different 'apply' functions, such as lapply,
sapply and many more. I'm very familiar with the 'Apply' function in
Mathematica. Can somebody point me a summary of all the 'apply'
functions in R. Also, I'm curious that what 'l' and 's' (and other
prefixes) stand for in 'lapply' and 'sapply'
Regards,
Peng
2018 Mar 13
0
Possible Improvement to sapply
Wouldn't that change how simplify='array' is handled?
> str(sapply(1:3, function(x)diag(x,5,2), simplify="array"))
int [1:5, 1:2, 1:3] 1 0 0 0 0 0 1 0 0 0 ...
> str(sapply(1:3, function(x)diag(x,5,2), simplify=TRUE))
int [1:10, 1:3] 1 0 0 0 0 0 1 0 0 0 ...
> str(sapply(1:3, function(x)diag(x,5,2), simplify=FALSE))
List of 3
$ : int [1:5, 1:2] 1 0 0 0 0 0 1 0 0