Re: [R] How to....

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Wed, 23 Jul 2008 21:06:20 +1000

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



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 23 Jul 2008 - 12:15:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Jul 2008 - 01:32:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive