[R] combining data from different datasets

Dr Eberhard W Lisse el at lisse.na
Fri Oct 24 17:37:30 CEST 2008


Gabor,

Thank you,

On 24 Oct 2008, at 17:16 , Gabor Grothendieck wrote:

> Here are two solutions.  The first uses the R merge command
> and the second uses the R sqldf package.  See ?merge
> and http://sqldf.googlecode.com
> Note that alter is an sql keyword so I have changed it
> to alt for the second example:
>
>> merge(iso, rawdata)[c("alt", "sex", "country")]
>  alter sex country
> 1    NA   M Andorra
> 2    39   F Namibia

merge(rawdata, iso, by.x = "cctld", by.y = "code", all.x = TRUE)
	[c("alter","sex", "cctld", "country")]

all.x = TRUE even pulls the cases with missing values

>
>> library(sqldf)
>
>> sqldf("select alt, sex, country from iso join rawdata  
>> using(country)")
>  alt sex country
> 1  NA   M Andorra
> 2  39   F Namibia

This looks very cool.

But I must still make a plan with regards to country = "NA" (Namibia)
or continent = "NA" (North America)

But there are the vignettes.

el



More information about the R-help mailing list