ect.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Massimo
Bressan
Sent: Thursday, October 3, 2013 9:42 AM
To: r-help@r-project.org
Subject: [R] storing element number of a list in a column data
frame
#let's suppose I have a list like this
mytest<-list(45, NULL, 18, NULL, 99)
#to note th
t.org"
Cc:
Sent: Thursday, October 3, 2013 10:41 AM
Subject: [R] storing element number of a list in a column data frame
#let's suppose I have a list like this
mytest<-list(45, NULL, 18, NULL, 99)
#to note that this is just an amended example because in fact
#I'm dealing with
the list I'm dealing with is the follow-up of an lapply() not a "native"
data structure I've been set up for storing data originally;
the list it's a data structure I have to manage as a consequence of my
previous operations, something like:
path<-"./"
files <-list.files(path, pattern=".csv")
my
4352
-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Massimo
Bressan
Sent: Thursday, October 3, 2013 9:42 AM
To: r-help@r-project.org
Subject: [R] storing element number of a list in a column data
frame
#let's suppose I have a list
Hi,
Something like this, maybe:
> mytest.df <- data.frame(i=seq_along(mytest)[!sapply(mytest, is.null)],
> n=unlist(mytest))
> mytest.df
i n
1 1 45
2 3 18
3 5 99
It took me a couple of tries, because I wasn't expecting unlist() to
drop the NULL values:
> unlist(mytest)
[1] 45 18 99
Sarah
O
Have you read An Introduction to R (ships with R) or another of the
many excellent R tutorials on the web? I ask, because you do not
appear to be using a sensible data structure. As your list appears to
be of a single type (probably numeric, maybe integer), it would be
preferable to use a vector, l
#let's suppose I have a list like this
mytest<-list(45, NULL, 18, NULL, 99)
#to note that this is just an amended example because in fact
#I'm dealing with a long list (more than 400 elements)
#with no evident pattern of the NULL values
#I want to end up with a data frame like the following
d
7 matches
Mail list logo