R/S-Plus: How can I merge two dataframes of different lengths?
-
Merging datasets in R. I seem to have forgotten how to do some things. I have a dataframe of individual-level data in which rows are individuals are columns are variables (257,597 individuals in 87 countries) . I also have a dataframe of country-level data in which rows are countries and columns are variables. I want to merge these two dataframes so that individuals have the country-level data as well (meaning that the country-level value is repeated for each individual in a country). The problem -- the country-level dataframe has 182 countries, meaning that some of the countries don't match what's in the individual-level dataframe. How can I merge these two dataframes without opening the country-level dataframe in Excel and removing by hand all of the countries that are not represented at the individual-level?
-
Answer:
This is simple. You want to use the merge command. Next time post the top part of each dataset by doing head(dataset_name). Regardless, I will assume the individual_id exists in both dataframes new_dataset=merge(individual_dataset,country_dataset,by="individual_id")
proj at Ask.Metafilter.Com Visit the source
Other answers
You'd think I would have gotten that given the subject of this question contains the word merge. I feel really stupid now. Thanks.
proj
Type in ?merge at the prompt for additional help.
special-k
Related Q & A:
- How do I compare two tables with the same column definitions in different schemas?Best solution by Database Administrators
- How can I merge all my Google calendars into my primary one?Best solution by Quora
- How do I bridge two different amps together?Best solution by ecoustics.com
- How can I make the layout with different colors?Best solution by Yahoo! Answers
- How can I connect two monitors to my laptop?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.