Displaying 20 results from an estimated 32 matches for "simplify2array".
2012 Oct 11
1
simplify2array edge case
Should simplify2array(higher=TRUE) treat 1 by 1 matrices differently than others?
I expected a 3-dimensional array from all of the following 3 examples, not just the last 2.
> str(simplify2array(list(array(11,c(1,1)), array(21,c(1,1))), higher=TRUE))
num [1:2] 11 21
> str(simplify2array(list(array(11:13,c(...
2024 Feb 08
1
Is simplify2array working for dimension > 2?
Reading the doc for ?simplify2array, I got the impression that with the
'higher = T' argument the function returns an array of dimension greater
than 2 when it makes sense (the doc says "when appropriate", which is
rather vague). I would expect
a <- list(
list(list(1, 2), list(3, 4)),
list(list(5, 6), list(7...
2024 Feb 08
1
Is simplify2array working for dimension > 2?
Jean-Claude:
Well, here's my "explanation". Caveat emptor!
Note that:
"simplify2array() is the utility called from sapply() when simplify is
not false"
and
> sapply(a, I, simplify = "array")
[,1] [,2]
[1,] list,2 list,2
[2,] list,2 list,2
So it seems that simplify2array() is not intended to operate in the
way that you expected, i.e. that recursive simplif...
2014 Mar 27
2
mclapply Segmentation Fault for Ubuntu
...()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(parallel)
> simplify2array(mclapply(rep(4, 5), rnorm))
*** caught segfault ***
address 0x7fee2a7229d0, cause 'memory not mapped'
Traceback:
1: mcexit(0L)
2: FUN(1:2[[1L]], ...)
3: lapply(seq_len(cores), inner.do)
4: mclapply(rep(4, 5), rnorm)
5: lapply(x, length)
6: unlist(lapply(x, length))
7: unique(unlis...
2013 Feb 14
3
list of matrices --> array
i'm somehow embarrassed to even ask this, but is there any built-in
method for doing this:
my_list <- list()
my_list[[1]] <- matrix(1:20, ncol = 5)
my_list[[2]] <- matrix(20:1, ncol = 5)
now, knowing that these matrices are identical in dimension, i'd like
to unfold the list to a 2x4x5 (or some other permutation of the dim
sizes) array.
i know i can initialize the array, then
2011 Aug 10
3
convert 'list' to 'vector'?
...\"j\")"
[3] "c(\"k\", \"l\")"
> as.vector(x)
[[1]]
[1] "a" "b" "c" "d" "e"
[[2]]
[1] "f" "g" "h" "i" "j"
[[3]]
[1] "k" "l"
> simplify2array(x)
[[1]]
[1] "a" "b" "c" "d" "e"
[[2]]
[1] "f" "g" "h" "i" "j"
[[3]]
[1] "k" "l"
What I would need to get instead is:
> letters[1:12]
[1] "a" "b" "...
2013 Aug 26
1
Loop for converting character columns to Numeric
Hi,
Suppose you created a dataframe like this:
set.seed(28)
?dat1<-as.data.frame(simplify2array(list(letters[1:5],sample(1:20,5,replace=TRUE),6:10)),stringsAsFactors=FALSE)
?str(dat1)
#'data.frame':??? 5 obs. of? 3 variables:
# $ V1: chr? "a" "b" "c" "d" ...
# $ V2: chr? "1" "2" "10" "18" ...
# $ V3: chr?...
2015 Apr 17
3
Redefining {
I am curious if anyone knows of R code where the "{" function is
redefined in a useful way. Or "(" for that matter.
Thanks
Mick
2018 Mar 13
4
Possible Improvement to sapply
...t;- function (X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE){
FUN <- match.fun(FUN)
answer <- lapply(X = X, FUN = FUN, ...)
if (USE.NAMES && is.character(X) && is.null(names(answer)))
names(answer) <- X
if (simplify && length(answer))
simplify2array(answer, higher = (simplify == "array"))
else answer
}
> microbenchmark(sapply(myList, length), times = 10000L)
Unit: microseconds
expr min lq mean median uq max neval
sapply(myList, length) 14.156 15.572 16.67603 15.926 16.634 650.46 10000
&g...
2013 Apr 25
2
Decomposing a List
Greetings!
For some reason I am not managing to work out how to do this
(in principle) simple task!
As a result of applying strsplit() to a vector of character strings,
I have a long list L (N elements), where each element is a vector
of two character strings, like:
L[1] = c("A1","B1")
L[2] = c("A2","B2")
L[3] = c("A3","B3")
2024 Apr 18
1
Tidyverse/dplyr solution for filling values of a tibble/dataframe from a column with a nested list.
Hi experts.
I have a tibble? with a column containing a nested list (<list<list<double>>>? data type to be specific).
Looks something like the following (but in R/Arrow? format):
ID
Nestedvals
001
[[1]](1,0.1)[[2]](2,0.2)[[3]](3,0.3)[[4]](4,0.4)[[5]](5,0.5)
002
[[1]](1,0.1)[[2]](2,0.2)[[3]](3,0.3)[[4]](4,0.4)
003
[[1]](1,0.1)[[2]](2,0.2)[[3]](3,0.3)
004
[[1]](1,0.1)[[2]](2,0.2)
2018 Mar 13
0
Possible Improvement to sapply
...= TRUE, USE.NAMES = TRUE){
> FUN <- match.fun(FUN)
> answer <- lapply(X = X, FUN = FUN, ...)
> if (USE.NAMES && is.character(X) && is.null(names(answer)))
> names(answer) <- X
> if (simplify && length(answer))
> simplify2array(answer, higher = (simplify == "array"))
> else answer
> }
>
>
> > microbenchmark(sapply(myList, length), times = 10000L)
> Unit: microseconds
> expr min lq mean median uq max neval
> sapply(myList, length) 14.156 15.572...
2012 Dec 31
3
weird bug with parallel, RSQlite and tcltk
Hello,
I spent a lot of a time on a weird bug, and I just managed to narrow it down.
In parallel code (here with parallel::mclappy, but I got it
doMC/multicore too), if the library(tcltk) is loaded, R hangs when
trying to open a DB connection.
I got the same behaviour on two different computers, one dual-core,
and one 2 xeon quad-core.
Here's the code:
library(parallel)
library(RSQLite)
2018 Mar 13
1
Possible Improvement to sapply
...unction (X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE){
FUN <- match.fun(FUN)
answer <- lapply(X = X, FUN = FUN, ...)
if (USE.NAMES && is.character(X) && is.null(names(answer)))
names(answer) <- X
if (simplify && length(answer))
simplify2array(answer, higher = (simplify == "array"))
else answer
}
> microbenchmark(sapply(myList, length), times = 10000L)
Unit: microseconds
expr min lq mean median uq max neval
sapply(myList, length) 14.156 15.572 16.67603 15.926 16.634 650.46 10000
&g...
2018 Mar 13
0
Possible Improvement to sapply
...fy = TRUE, USE.NAMES = TRUE){
> FUN <- match.fun(FUN)
> answer <- lapply(X = X, FUN = FUN, ...)
> if (USE.NAMES && is.character(X) && is.null(names(answer)))
> names(answer) <- X
> if (simplify && length(answer))
> simplify2array(answer, higher = (simplify == "array"))
> else answer
> }
>
>
>> microbenchmark(sapply(myList, length), times = 10000L)
> Unit: microseconds
> expr min lq mean median uq max neval
> sapply(myList, length) 14.156 15....
2018 Mar 13
2
Possible Improvement to sapply
...fy = TRUE, USE.NAMES = TRUE){
> FUN <- match.fun(FUN)
> answer <- lapply(X = X, FUN = FUN, ...)
> if (USE.NAMES && is.character(X) && is.null(names(answer)))
> names(answer) <- X
> if (simplify && length(answer))
> simplify2array(answer, higher = (simplify == "array"))
> else answer
> }
>
>
>> microbenchmark(sapply(myList, length), times = 10000L)
> Unit: microseconds
> expr min lq mean median uq max neval
> sapply(myList, length) 14.156 15....
2020 Apr 04
5
Help useRs to use R's own Time/Date objects more efficiently
...) {
DF <- as.data.frame(unclass(as.POSIXlt( dt )), stringsAsFactors=stringsAsFactors)
`names<-`(cbind(dt, DF, deparse.level=0L), c(dName, names(DF)))
}
dt2df(.leap.seconds) # date+time
dt2df(Sys.Date() + 0:9) # date
##' Even simpler: Date -> Matrix:
d2mat <- function(x) simplify2array(unclass(as.POSIXlt(x)))
d2mat(seq(as.Date("2000-02-02"), by=1, length.out=30)) # has R 1.0.0's release date
------------------------------------------------------------
In the distant past / one of the last times I touched on people
using (base) R's Date / Time-Date objects, I...
2012 Mar 30
1
How to use access results of gregexpr in data frames
Hello,
I'm trying to figure out how to find the index of the second occurrence of "/" in a string (which happens to represent a date) within a data frame column.
I've used the following code successfully to find the first instance of "/".
dframe <- data.frame(date=c("5/14/2011", "4/7/2011"))
dframe$x1 <- regexpr("/", dframe[, 1])
2011 Nov 15
2
using tapply() with the quantile function?
Hi:
Summary:
I am trying to determine the 90th percentile of ambulance response times for groups of data.
Background:
A fire chief would like to look at emergency response times at the 90th percentile for 1 kilometer grids in Cape Coral, Florida. I have mapped out ambulance response times on a GIS map. Then I superimpose a regularly-spaced grid over the response times and spatially join the
2013 Mar 11
3
take two columns from a set of lists
say I have a matrix and lists like
x <- matrix(c(12.1, 3.44, 0.1, 3, 12, 33.1, 1.1, 23), nrow=2)
x.list <- lapply(seq_len(nrow(x)), function(i) x[i,])
if I want a column of the matrix x, I write
x[, 2]
for example.
But how can I do something similar for a set of lists, x.list, above?
> x.list
[[1]]
[1] 12.1 0.1 12.0 1.1
[[2]]
[1] 3.44 3.00 33.10 23.00
unlist(x.list)[,2] does