ware
> wdunlap tibco.com
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
>> Behalf
>> Of R. Michael Weylandt
>> Sent: Thursday, August 09, 2012 4:22 PM
>> To: arun
>> Cc: R help;
tibco.com
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> Of R. Michael Weylandt
> Sent: Thursday, August 09, 2012 4:22 PM
> To: arun
> Cc: R help; jimi adams
> Subject: Re: [R] indexing in data frames
>
On Thu, Aug 9, 2012 at 5:30 PM, arun wrote:
>
> lapply(1:length(a$c),function(x) a$b[x]-a$c[[x]])
Arun,
I've seen you use this idiom a few times lately and I'd just like to note that
seq_along()
is an (underutilized) primitive and a safer and faster alternative
(avoiding the pathological leng
Other way:
b<-c(1988,1989,1990,1991,1992)
c=list(c(1985,1982,1984),c(1988,1980),c(1983,1984),c(1988,1998,1993),c(1993,1994,1998))
a<-data.frame(b,c1=cbind(c))
a
b c
1 1988 1985, 1982, 1984
2 1989 1988, 1980
3 1990 1983, 1984
4 1991 1988, 1998, 1993
5 1992 1993, 1
Thanks. Yes, I got it to work with loops for small data. I was just hoping,
given the size of the data.frame (hundreds of thousands) and the length of the
lists (varying up to a few hundred) to avoid that if at all possible. Perhaps
I'm expecting some behavior that's not feasible?
cheers,
jimi
HI,
In the reply I sent, I forgot to add,
anew<-list()#before,
for(i in 1:length(b1)){
anew[[i]]<-list()
anew[[i]]<-b1[[i]]-c[[i]]
}
A.K.
- Original Message -
From: jimi adams
To: r-help@r-project.org
Cc:
Sent: Thursday, August 9, 2012 4:42 PM
Subject: [R] indexing in data frames
HI,
You can get the results you wanted by:
c=list(c(1985,1982,1984),c(1988,1980),c(1983,1984),c(1988,1998,1993),c(1993,1994,1998))
b1<-list(1988,1989,1990,1991,1992)
for(i in 1:length(b1)){
anew[[i]]<-list()
anew[[i]]<-b1[[i]]-c[[i]]
}
anew
[[1]]
[1] 3 6 4
[[2]]
[1] 1 9
---
---
But, i
ge -
From: jimi adams
To: arun
Cc: R help
Sent: Thursday, August 9, 2012 5:42 PM
Subject: Re: [R] indexing in data frames
Thanks. Yes, I got it to work with loops for small data. I was just hoping,
given the size of the data.frame (hundreds of thousands) and the length of the
lists (varying
> -Original Message-
> From: David Winsemius [mailto:dwinsem...@comcast.net]
> Sent: Thursday, August 09, 2012 5:17 PM
> To: dcarl...@tamu.edu
> Cc: 'jimi adams'; r-help@r-project.org
> Subject: Re: [R] indexing in data frames
>
>
> On Aug 9, 2012, at 2:43 PM, D
On Aug 9, 2012, at 2:43 PM, David L Carlson wrote:
You have not defined a data frame since data frames cannot contain
lists,
Not true:
> dput(a)
structure(list(b = c(1988, 1989),
c = list(c(1985, 1982, 1984),
c(1988, 1980))), .Names = c("b", "c"))
> a
You have not defined a data frame since data frames cannot contain lists,
but lists can contain data frames so you are asking about how to process a
list. I'm changing your object names to a, b, and d because c() is the
concatenation function and it can cause all kinds of problems to use it as
an o
11 matches
Mail list logo