[R] xyplot formula

Phil Spector spector at stat.berkeley.edu
Fri Feb 18 08:12:45 CET 2011


Geoff -
    I think this will get you closer to a solution:

newdf = reshape(df,varying=names(df)[-c(1,2)],direction='long',
                 times=2000:2003,idvar=c('country','food'),v.names='X',
                 timevar='year')

xyplot(X~year|country*food,data=newdf)
 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu



On Fri, 18 Feb 2011, Geoff Russell wrote:

> df=data.frame(country=c("A","A","A","B","B","B"),
>    food=rep(c("Apples","Pears","Bananas"),2),
>    X2000=c(4,5,6,7,6,8),
>    X2001=c(4,5,6,7,6,8),
>    X2002=c(4,5,6,7,6,8),
>    X2003=c(4,5,6,7,6,8));
>
> I have data in the above form trying to get a plot of each fruit over time
> year conditioned on country and food.
>
> I tried,
>
> xyplot(X2000+X2001+X2002+X2003~2000:2003|country*food,df)
>
> But think I need to transform the data, just not sure
> how.  Any help gratefully received.
>
> Cheers,
> Geoff.
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list