[R] How to....

Jia Ying Mei jiamei at Princeton.EDU
Fri Jul 25 03:07:27 CEST 2008


Hi,

Thanks a lot Jim, but I've encountered an error while performing your 
steps. This is my code, essentially straightforwardly following yours:

 > fmt<-"%m/%d/%y"
 > dd<-read.csv("Desktop/R/CDSdate.txt")
 > dd$Date<-as.Date(dd$Date,fmt)
 > library(zoo)

Attaching package: 'zoo'


    The following object(s) are masked from package:base :

     as.Date.numeric

 > z<-read.zoo("Desktop/R/Countrydata.txt", header=TRUE, format = fmt)
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, 
na.strings,  :
  line 1 did not have 93 elements

I'm perplexed as to why line 1(column 1?) needs 93 elements and why I 
should have that many. Any help would be awesome, thanks!

Jia Ying Mei

Jim Lemon wrote:
> On Tue, 2008-07-22 at 16:31 -0400, Jia Ying Mei wrote:
>   
>> Hi everyone,
>>
>> I am not new to R, but its been over a year since I've used it, so I 
>> don't remember how to do some things.
>>
>> I have a data set (in excel currently, but will be converted to text), 
>> that has date, country and price, with a price for every country for 
>> every date. I need to find the mean and median of the interval between 
>> price changes for each country and the mean and median percentage change 
>> for each price change within the data for a single country.
>>
>> How should I go about doing this? I'd appreciate any help.
>>     
>
> Hi Jia,
> I'm not too sure what you mean by the second set of means and medians,
> but this should get you started:
>
> # first make up some data
> jym.df<-data.frame(country=rep(c("au","br""cn","in","us"),each=100),
>  date=rep(as.Date("02/02/2008",
>   format="%d/%m/%Y"),500)+sample(-40:40,500,TRUE),
>  price=rnorm(500,100,20))
> # get the intervals by country - have to create a new data frame
> jymint.df<-data.frame(country=rep(levels(jym.df$country),each=99),
>  intervals=unlist(tapply(jym.df$date,jym.df$country,diff)))
> library(prettyR)
> # break down the intervals by country
> brkdn(intervals~country,jymint.df,num.desc=c("mean","median"))
>
> Jim
>
>
>   
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Countrydata.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080724/a91ddb07/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CDSdate.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080724/a91ddb07/attachment-0001.txt>


More information about the R-help mailing list