I'm working with some data in R, and I have a dataframe with data from areas and mining projects, so some areas have more than one type of project. In this case, I would like to gather data from areas that have the same name, differentiating only the types of projects that each area has, as in the example below:
- Example of how my table looks
- How would I like to organize them:
CodePudding user response:
Do you want to restructure your data, or present a table in use for data visualization?
If you want to restructure your data, you can either use dplyr::chop()
or dplyr::nest()
.
In your case, dplyr::chop()
is most likely what you want. The links provided show some great examples. If your frame is called df
, this is how you might use it:
nested_df <- chop(df, c(mining, project_number))