Sabrina Xie
Sabrina Xie

Reputation: 108

Reorganizing a dataframe in R?

I'm new and not sure how to look this up, but I am trying to create a model from some data I was given. The data is organized so that the columns are:

There are multiple observations at each site over time and 2 parameters at each observation. I want to instead organize it so that each unique observation at each site is a row and the value of each parameter is in a column with the name of the parameter as the column name. So:

I figured I could merge the SITE ID and DATE to create a sort of unique ID for each observation, but can't figure out how to basically match that within the dataframe to look for the other value.

Upvotes: 0

Views: 35

Answers (1)

akrun
akrun

Reputation: 887831

We could do this with pivot_wider

library(tidyr)
pivot_wider(df1, names_from = 'PARAMETER NAME', values_from = 'VALUE')

Upvotes: 1

Related Questions