Displaying 20 results from an estimated 20000 matches similar to: "getting the "name" of an object"
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
2018 Mar 13
1
Possible Improvement to sapply
You?re right, it sure does. My suggestion causes it to fail when simplify = ?array?
From: William Dunlap [mailto:wdunlap at tibco.com]
Sent: Tuesday, March 13, 2018 12:11 PM
To: Doran, Harold <HDoran at air.org>
Cc: r-help at r-project.org
Subject: Re: [R] Possible Improvement to sapply
Wouldn't that change how simplify='array' is handled?
> str(sapply(1:3,
2018 Mar 13
0
Possible Improvement to sapply
On 03/13/2018 09:23 AM, Doran, Harold wrote:
> While working with sapply, the documentation states that the simplify argument will yield a vector, matrix etc "when possible". I was curious how the code actually defined "as possible" and see this within the function
>
> if (!identical(simplify, FALSE) && length(answer))
>
> This seems superfluous to me,
2018 Mar 13
4
Possible Improvement to sapply
While working with sapply, the documentation states that the simplify argument will yield a vector, matrix etc "when possible". I was curious how the code actually defined "as possible" and see this within the function
if (!identical(simplify, FALSE) && length(answer))
This seems superfluous to me, in particular this part:
!identical(simplify, FALSE)
The preceding
2018 Mar 13
2
Possible Improvement to sapply
Martin
In terms of context of the actual problem, sapply is called millions of times because the work involves scoring individual students who took a test. A score for student A is generated and then student B and such and there are millions of students. The psychometric process of scoring students is complex and our code makes use of sapply many times for each student.
The toy example used
2011 May 25
3
Accessing elements of a list
I have a list that is made of lists of varying length. I wish to create a
new vector that contains the last element of each list. So far I have used
sapply to determine the length of each list, but I'm stymied at the part
where I index the list to make a new vector containing only the last item
of each list
mylist =
2018 Mar 13
1
Possible Improvement to sapply
Could your code use vapply instead of sapply? vapply forces you to declare
the type and dimensions
of FUN's output and stops if any call to FUN does not match the
declaration. It can use much less
memory and time than sapply because it fills in the output array as it goes
instead of calling lapply()
and seeing how it could be simplified.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Tue,
2007 Jun 22
2
extract index during execution of sapply
Hi there
During execution of sapply I want to extract the number of times the
function given to supply has been executed. I came up with:
mylist <- list(a=3,b=6,c=9)
sapply(mylist,function(x)as.numeric(gsub("[^0-9]","",deparse(substitute(x)))))
This works fine, but looks quite ugly. I'm sure that there's a more
elegant way to do this.
Any suggestion?
Christian
2018 Mar 13
0
Possible Improvement to sapply
Quite possibly, and I?ll look into that. Aside from the work I was doing, however, I wonder if there is a way such that sapply could avoid the overhead of having to call the identical function to determine the conditional path.
From: William Dunlap [mailto:wdunlap at tibco.com]
Sent: Tuesday, March 13, 2018 12:14 PM
To: Doran, Harold <HDoran at air.org>
Cc: Martin Morgan <martin.morgan
2011 Jan 15
3
get list element names within lapply / sapply call
Hi all,
I would like to iterate through a list with named elements and access the
names within an lapply / sapply call. One way to do this is iterate through
the names and index the list with the name. Is there a way to iterate
through the list elements themselves and access the element names within in
the function? For example,
mylist <-
2016 Dec 02
2
pdftools on Ubuntu
Hi,
I am trying to install pdftools package on R 3.3.1 (Ubuntu 16.04), but the
following issue occurs:
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because poppler-cpp was not found. Try installing:
* deb: libpoppler-cpp-dev (Debian, Ubuntu, etc)
* rpm: poppler-cpp-devel (Fedora, CentOS, RHEL)
* csw: poppler_dev (Solaris)
* brew: poppler (Mac OSX)
2010 Mar 18
1
Substitute NAs in a data frame
Excuse me for what I'm sure is a stupid beginner's question, but I've
given up trying to find the answer to this question from the help,
RSiteSearch, or any of the usual places.
I have a list that looks like this:
>myList
$first
[1] "--" "18" "8" "32"
$second
[1] "--" "--" "40" "54"
I want a
2009 Sep 02
2
Average over data sets
Hello,
I have a number of files output1.dat, output2.dat, ... , output20.dat,
each of which monitors several variables over a fixed number of
timepoints. From this I want to create a data frame which contains the
mean value between all files, for each timepoint and each variable.
The code below works, but it seems like I should be able to do the
second part without a for loop. I played
2016 Dec 02
1
pdftools on Ubuntu
Hi Francois,
Thanks for your quick response.
Actually, I had already done that...
sudo apt-get install libpoppler-cpp-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libpoppler-cpp-dev is already the newest version (0.41.0-0ubuntu1.1).
0 upgraded, 0 newly installed, 0 to remove and 107 not upgraded.
Therefore, I assume I have this installed.
Best
2004 Feb 26
3
my own function given to lapply
Hi
It seems, I just miss something. I defined
treshold <- function(pred) {
if (pred < 0.5) pred <- 0 else pred <- 1
return(pred)
}
and want to use apply it on a vector
sapply(mylist[,,3],threshold)
but I get:
Error in match.fun(FUN) : Object "threshold" not found
thanks for help
cheers
chris
--
Christoph Lehmann <christoph.lehmann at gmx.ch>
2010 Sep 04
4
Please explain "do.call" in this context, or critique to "stack this list faster"
I've been doing some consulting with students who seem to come to R
from SAS. They are usually pre-occupied with do loops and it is tough
to persuade them to trust R lists rather than keeping 100s of named
matrices floating around.
Often it happens that there is a list with lots of matrices or data
frames in it and we need to "stack those together". I thought it
would be a simple
2005 Mar 16
8
Summing up matrices in a list
Dear all,
I think that my question is very simple but I failed to solve it.
I have a list which elements are matrices like this:
>mylist
[[1]]
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
[[2]]
[,1] [,2] [,3]
[1,] 7 9 11
[2,] 8 10 12
I'd like to create a matrix M<-mylist[[1]]+mylist[[2]]
[,1] [,2] [,3]
[1,] 8 12 16
[2,] 10 14 18
2007 Feb 21
1
Trying to get an apply to work with a list in applying names to tables
I am trying to use apply and a list to supply names
to a set of tables I want to generate. Below is an
example that I hope mimics the larger original
problem.
EXAMPLE
aa <- c( 2,2,1,1,2)
bb <- c(5,6,6,7,4)
aan <- c("yes", "no")
bbn <- c("a", "b", "c", "d")
mynames <- c("abby", "billy")
mylist <-
2018 Mar 13
2
Possible Improvement to sapply
FYI, in R devel (to become 3.5.0), there's isFALSE() which will cut
some corners compared to identical():
> microbenchmark::microbenchmark(identical(FALSE, FALSE), isFALSE(FALSE))
Unit: nanoseconds
expr min lq mean median uq max neval
identical(FALSE, FALSE) 984 1138 1694.13 1218.0 1337.5 13584 100
isFALSE(FALSE) 713 761 1133.53 809.5 871.5
2010 Mar 26
5
smart way to turn a vector into a matrix
Hello guys, I am working on a matrix which looks like this one:
> initialMatrix <-
> rbind(cbind(rep("A",3),seq(1,3)),cbind(rep("B",4),seq(1,4)),cbind(rep("C",3),seq(1,3)))
> initialMatrix
[,1] [,2]
[1,] "A" "1"
[2,] "A" "2"
[3,] "A" "3"
[4,] "B" "1"
[5,]