[R] data.frame - transform

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Fri Jun 14 11:13:04 CEST 2002


"Patrick Hausmann" <patrick.hausmann at uni-bremen.de> writes:

> Hi there,
> 
> I have a data.frame (pwt6) which I would like to transform:
> 
> country	year	gdp
> MEX	1950	2
> MEX	1951	5
> BOL	1950	4
> BOL	1951	12
> ITA	1950	45
> ITA	1951	2
> 
> This should be the result:
> year	MEX.gdp	BOL.gdp	ITA.gdp
> 1950	2		4		45
> 1951	5		12		2
> 
> Right now I have this code (better - no code):
> country.label<-names(table(pwt6$country)) 
> result<-data.frame(year=NULL)
>  for(i in country.label)
>    ?

This is what reshape() is for.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list