[R] combining data from different datasets
Daniel Malter
daniel at umd.edu
Fri Oct 24 21:24:20 CEST 2008
?merge.
It looks though that your "iso" has no identifier variable whereas the
"rawdata" has, so you probably cannot merge it unless/until you have an
identifier in "iso". If you know that all data is already ordered
accordingly, you can just bind the columns together in a new object like
this:
newdata=data.frame(rawdata$alter,rawdata$sex,iso$country)
newdata #return newdata
Cheers,
Daniel
-------------------------
cuncta stricte discussurus
-------------------------
-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von Dr Eberhard W Lisse
Gesendet: Friday, October 24, 2008 11:02 AM
An: R-help Mailing List
Cc: Dr Eberhard W Lisse
Betreff: [R] combining data from different datasets
Hi,
I have two tables:
> iso
continent code code3 codenum country
1 EU AD AND 20 Andorra, Principality of
2 AS AE ARE 784 United Arab Emirates
3 AS AF AFG 4 Afghanistan, Islamic Republic of
4 NA AG ATG 28 Antigua and Barbuda
5 NA AI AIA 660 Anguilla
159 AF NA NAM 516 Namibia, Republic of
...
246 AF ZW ZWE 716 Zimbabwe, Republic of
and
> rawdata
idno alter sex cctld capacity topics content speakers
1 1 NA M AD A 2 1 2
2 2 52 M <NA> A 3 2 2
3 3 39 F NA T 2 2 2
...
How do I make it print out something like
alter sex country
1 NA M Andorra, Principality of
2 39 F Namibia, Republic of
...
in other words do something like the following SQL:
SELECT r.alter, r.sex, i.country
FROM iso i, rawdata r
WHERE i.code = r.cctld
or even better:
alter sex country
1 NA M Andorra, Principality of
2 52 M <NA>
3 39 F Namibia
...
And idea (where I can read up on this)?
el
--
Dr. Eberhard W. Lisse \ / Obstetrician & Gynaecologist (Saar)
el at lisse.NA el108-ARIN / * | Telephone: +264 81 124 6733 (cell)
PO Box 8421 \ / Please send DNS/NA-NiC related e-mail
Bachbrecht, Namibia ;____/ to dns-admin at na-nic.com.na
______________________________________________
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