To create a dataset with two variable name columns and one value column, and then use pivot_wider
to change the dataframe to wide format in R, you can use the following code:
main.r482 chars21 lines
In this example, category1
is used as the id column, category2
is used to create new column names, and value
is used to fill the new columns. The resulting data_wide
dataframe will have a wide format with category1
as the unique identifier and separate columns for each level of category2
.
The output will look like this:
main.r75 chars5 lines
gistlibby LogSnag