I did the following
DF<-do.call(rbind, pp2)
DF1=na.omit(DF)
DF1[,2]=as.Date(DF1[,2])
str(DF)
'data.frame': 18660 obs. of 6 variables:
I tried the following code
temp<-lapply(split(DF1,DF1$Trade.Date), function(.df) {
+
data.frame(DATE=.df$Trade.Date,RANGE=max(.df$New.Price)-min(.df$New.Pric
e))
+ })
temp[[1]][1:5,]
DATE RANGE
1 2006-12-29 1276.670
2 2006-12-29 1276.670
3 2006-12-29 1276.670
4 2006-12-29 1276.670
5 2006-12-29 1276.670
What am I doing wrong?
I also tried the below and that seemed to give me the range
nn=tapply(DF1$New.Price, DF1$Trade.Date, range)
$`2006-12-29`
[1] 0.0074638 1276.6772880
$`2006-12-31`
[1] 4.673445 227.600000
$`2007-01-31`
[1] 0.0030772 1255.2080450
$`2007-02-28`
[1] 0.003978 1316.638200
$`2007-03-29`
[1] 5.25585 216.20000
$`2007-03-30`
[1] 0.0047214 1266.8250000
Thanks
Ravi Shankar S
-----Original Message-----
From: jim holtman [mailto:jholtman at gmail.com]
Sent: Thursday, March 27, 2008 2:49 AM
To: Ravi S. Shankar
Cc: r-help at stat.math.ethz.ch; markleeds at verizon.net
Subject: Re: [R] Range across a List
I think something like this should work. I will give you the range
for each date across all the data:
x <- do.call(rbind, pp2)
tapply(x$New.Price, x$Trade.Date, range)
On 3/26/08, Ravi S. Shankar <ravis at ambaresearch.com> wrote:
To add more clarity to my question
My data pp2 is a list
(pp2[[1]])
RIC Trade.Date Close.Price Currency.Code Convertion.Rate
ABCD.SZ 2008/02/29 15.30 CNY 0.1408
2.154240
ABCD.SZ 2008/01/31 15.27 CNY 0.1392
2.040048
ABCD.SZ 2007/11/30 11.07 CNY 0.1357
1.502199
ABCD.SZ 2007/10/31 10.89 CNY 0.1340
1.459260
ABCD.SZ 2007/09/28 12.77 CNY 0.1334
1.703518
(pp2[[2]])
RIC Trade.Date Close.Price Currency.Code Convertion.Rate
New.Price
PQRS.SZ 2008/02/29 9.27 CNY 0.1408
PQRS.SZ 2008/01/31 8.07 CNY 0.1392
PQRS.SZ 2007/12/31 8.76 CNY 0.1371
PQRS.SZ 2007/11/30 6.43 CNY 0.1357
PQRS.SZ 2007/10/31 6.80 CNY 0.1340
PQRS.SZ 2007/09/28 7.94 CNY 0.1334
And so on till (pp2[[1244]])
Each of pp2[[i]] is a data frame. For each date I need to find the
of New.Price across the list
i.e.for 2008/02/29 it would be
max(pp2[[i]]$New.Price[1])-min(pp2[[i]]$New.Price[1]) where i ranges
from 1 to 1244
Thank you,
Ravi
-----Original Message-----
From: markleeds at verizon.net [mailto:markleeds at verizon.net]
Sent: Thursday, March 27, 2008 2:12 AM
To: Ravi S. Shankar
Subject: Re: [R] Range across a List
From: "Ravi S. Shankar" <ravis at ambaresearch.com>
Date: 2008/03/26 Wed PM 03:28:52 CDT
To: r-help at stat.math.ethz.ch
Subject: [R] Range across a List
i think it's a dataframe ( it looks
like one ) or convert it to
one if it's not and then I think below should
work.
temp<-lapply(split(pp2,pp2$Trade.Date), function(.df)
{
data.frame(.df$Trade.Date[1],range(.df$New.Price))
})
result<-do.call(rbind,temp)
test it though because i didn't.
[1] 1244
It is in the below format
RIC Trade.Date Close.Price Currency.Code Convertion.Rate
ABCD.SZ 2008/02/29 15.30 CNY 0.1408 2.154240
ABCD.SZ 2008/01/31 15.27 CNY 0.1392 2.125584
ABCD.SZ 2007/12/31 14.88 CNY 0.1371 2.040048
ABCD.SZ 2007/11/30 11.07 CNY 0.1357 1.502199
ABCD.SZ 2007/10/31 10.89 CNY 0.1340 1.459260
ABCD.SZ 2007/09/28 12.77 CNY 0.1334 1.703518
I want to find the range of pp2$New.Price for length(pp2) for each
Any help would be appreciated
Thanks in advance
Ravi
This e-mail may contain confidential and/or privileged