Home > Back-end >  how do I join and center attributes of the same name in a DataFrame in R?
how do I join and center attributes of the same name in a DataFrame in R?

Time:10-29

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

enter image description here

  • How would I like to organize them:

enter image description here

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))
  • Related