Displaying 20 results from an estimated 337 matches for "mylist".
Did you mean:
mlist
2017 Jun 15
4
is.null(mylist[1]) and is.null(mylist$a) returns different values
Hi
I have a list :
mylist <- list( a = NULL, b = 1, c = 2 )
> mylist[1]
$a
NULL
> is.null(mylist[1])
[1] FALSE
> is.null(mylist$a)
[1] TRUE
why? I need to use mylist[1]
2015 May 04
2
Define replacement functions
Hello
I tried to define replacement functions for the class "mylist". When I test them in an active R session, they work -- however, when I put them into a package, they don't. Why and how to fix?
make_my_list <- function( x, y ) {
return(structure(list(x, y, class="mylist")))
}
mylist <- make_my_list(1:4, letters[3:7])
mylist
mylist[[...
2009 Oct 25
3
NULL elements in lists ... a nightmare
I can define a list containing NULL elements:
> myList <- list("aaa",NULL,TRUE)
> names(myList) <- c("first","second","third")
> myList
$first
[1] "aaa"
$second
NULL
$third
[1] TRUE
> length(myList)
[1] 3
However, if I assign NULL to any of the list element then such
element is deleted...
2010 Sep 09
0
Fast / dependable way to "stack together" data frames from a list
...We face this problem all the time. A procedure
generates a list of data frames. How to stack them
together?
The short answer is that the plyr package's rbind.fill
method is probably the fastest method that is not
prone to trouble and does not require much user caution.
result <- rbind.fill(mylist)
A slower alternative that also works is
result <- do.call("rbind", mylist)
That is always available in R and it works well enough, even
though it is not quite as fast. Both of these are much faster than
a loop that repeatedly applies "rbind".
Truly blazing speed can be...
2017 Jun 15
0
is.null(mylist[1]) and is.null(mylist$a) returns different values
Hi,
Try
> is.null(mylist[[1]])
[1] TRUE
Notice the double square brackets.
From: ?`[`
"The most important distinction between [, [[ and $ is that the [ can
select more than one element whereas the other two select a single
element."
On Thu, Jun 15, 2017 at 11:33 AM, ce <zadig_1 at excite.com> wrote:
>...
2010 May 17
3
applying quantile to a list using values of another object as probs
Hi r-users,
I have a matrix B and a list of 3x3 matrices (mylist). I want to
calculate the quantiles in the list using each of the value of B as
probabilities.
The codes I wrote are:
B <- matrix (runif(12, 0, 1), 3, 4)
mylist <- lapply(mylist, function(x) {matrix (rnorm(9), 3, 3)})
for (i in 1:length(B))
{
quant <- lapply (mylist, quant...
2001 Oct 18
2
Parsing for list components
How do I parse an identifier of a list component, e.g.
mylist$mycomponent
or
mylist[[1]] ?
Parse does not do the job, e.g.
parse(text="mylist$mycomponent")
returns an expression with just one term, instead of "mylist", "$",
"mycomponent".
What I need is a way to extract the list name (e.g. "mylist"), given...
2004 May 10
2
Lists and outer() like functionality?
Hi,
I'm have a list of integer vectors and I want to perform an outer()
like operation on the list. As an example, take the following list:
mylist <- list(1:5,3:9,8:12)
A simple example of the kind of thing I want to do is to find the sum
of the shared numbers between each vector to give a result like:
result <- array(c(15,12,0,12,42,17,0,17,50), dim=c(3,3))
Two for() loops is the easiest way but I wondered if there was a
neater/fa...
2010 Sep 04
4
Please explain "do.call" in this context, or critique to "stack this list faster"
...do.call is
not the fastest, but it does appear to be the least prone to
programmer error.
I have been staring at ?do.call for quite a while and I have to admit
that I just need some more explanations in order to interpret it. I
can't really get why this does work
do.call( "rbind", mylist)
but it does not work to do
sapply ( mylist, rbind).
Anyway, here's the self contained working example that compares the
speed of various approaches. If you send yet more ways to do this, I
will add them on and then post the result to my Working Example
collection.
## stackMerge.R
## Paul...
2017 Jun 15
1
is.null(mylist[1]) and is.null(mylist$a) returns different values
I find that the str function is more helpful for understanding the difference between a null list and a list containing a null list than the implicit print function call that the interpreter invokes when you enter an expression at the console.
str( mylist[1] )
--
Sent from my phone. Please excuse my brevity.
On June 15, 2017 8:39:47 AM PDT, Huzefa Khalil <huzefa.khalil at umich.edu> wrote:
>Hi,
>
>Try
>
>> is.null(mylist[[1]])
>[1] TRUE
>
>Notice the double square brackets.
>
>From: ?`[`
>"The most i...
1999 May 09
1
subscripting in list() (PR#187)
Sorry My previous report is not detailed.
In R, you will get this:
> mylist <- list()
> mylist[[1]]
Error in mylist[[1]] : subscript out of bounds
> mylist[[1]] <- c(1)
Error: (list) object cannot be coerced to vector type 14
> mylist[[1]] <- c(1,2)
> mylist[[1]] <- c(1)
> mylist
[[1]]
[1] 1
I was trying to assigning c(1) to (mylist[[1]] <- c...
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
Is there a way to create M without loopi...
2007 Oct 20
1
Getting at what a named object represents in a function...
Hi,
I'm pretty new to R.
I have an object (say a list) and I I have a function that I call on
various columns in that list (excuse terminology if it's wrong/ambiguous).
Imagine its like this (actual values are unimportant) and called mylist:
>mylist
A B
1 5
2 5
3 6 4 8
5 0
I have a function:
foo = function(param){
#modify list A or B values depending on whether A or B's passsd in (via
'param')
param[someindex]=another_value #doesn't change value in lits$A or
list$B (whichever's been...
2017 Jun 15
0
is.null(mylist[1]) and is.null(mylist$a) returns different values
Thank you all , very informative, never thought of doing a str( mylist[1] )
-----Original Message-----
From: "Jeff Newmiller" [jdnewmil at dcn.davis.ca.us]
Date: 06/15/2017 11:56 AM
To: r-help at r-project.org, "Huzefa Khalil" <huzefa.khalil at umich.edu>, "ce" <zadig_1 at excite.com>
Subject: Re: [R] is.null(mylist[1]) and...
2015 May 04
1
Define replacement functions
No. I fixed that, the NAMESPACE file now contains:
S3method("[[<-", mylist)
S3method("$<-", mylist)
It still does not work. I also created a print method (print.mylist) which did work out of the box, regardless of being in the NAMESPACE file or not. Could it be somehow in here (also in my NAMESPACE file):
exportPattern("^[[:alpha:]]+")
Or could i...
2011 Apr 05
1
Help in splitting a list
Dear R users,
Let's say I have a list with components being 'm' matrices (as exemplified
in the "mylist" object below). Now, I'd like to subset this list based on an
index vector, which will partition each matrix 'm' in 2 sub-matrices. My
questions are:
1. Is there an elegant way to have the results shown in mylist2 for an
arbitrary number of matrices in mylist?
2. The column names...
2012 Aug 28
3
Get variable data Reading from the list
Here i have a variable
MyVar <- data.frame(read.csv("D:\\Doc.csv"))
And now i am storing this variable name into a list.
MyList <- list()
MyList [length(MyList )+1]<- "MyVar"
Now what is the requirement is,
i need to call the variable name "MyVar" from the list "MyList " and get
the data.
---------------------------------------------------------------------------------------------------...
2007 Jun 29
2
regexpr
Hi,
I 'd like to match each member of a list to a target string, e.g.
------------------------------
mylist=c("MN","NY","FL")
g=regexpr(mylist[1], "Those from MN:")
if (g>0)
{
"On list"
}
------------------------------
My question is:
How to add an end-of-string symbol '$' to the to-match string? so that 'M'
won't match.
Of course...
2011 May 25
3
Accessing elements of a list
...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 = list(c(1,2,3),c("cat","dog"),c("x","y","z","zz")) # Create
list
last <- sapply(mylist,length) # Make vector with list lengths
last_only <- mylist[[1:length(mylist)]][last] # Crash and burn trying to
make new vector with...
2005 Jan 30
3
trellis graphics in loops
...rnorm(10000), y=rnorm(10000), z=sample(c("foo1","foo2"),
10000,replace=T), year=sample(c(89:94), 10000,replace=T))
trellis.device("postscript", file="foo.eps")
for(i in unique(X$year)){
temp <- X[X$year%in%i, ]
xyplot(temp$x~temp$y|temp$z)
}
dev.off()
mylist <- list()
for(i in unique(X$year)){
temp <- X[X$year%in%i, ]
mylist[[i]] <- xyplot(temp$x~temp$y|temp$z)
}
trellis.device("postscript", file="foo1.eps")
mylist[[89]]
mylist[[90]]
mylist[[91]]
mylist[[92]]
mylist[[93]]
mylist[[94]]
dev.off()
Thank you,
Jean