How to consolidate observations in a data frame based on values in one column and and spread variables to new columns

31 Views Asked by At

I have a dataframe:

v1 <- c("Bob", "Bob", "Fred", "Fred")
v2 <- c("Age", "KG", "Age", "KG")
v3 <- c(25, 80, 30, 90)
df <- data.frame(v1,v2,v3)
df
    v1  v2 v3
1  Bob Age 25
2  Bob  KG 80
3 Fred Age 30
4 Fred  KG 90

I would like to consolidate the data so the table looks like this:

  V1   Age   KG
1 Bob  25    80
2 Fred 30    90

I have tried a variety of tidyr and dplyr functions without success.

0

There are 0 best solutions below