gistlib
library(tidyr) # Example dataframe df <- data.frame(id = c(1, 1, 2, 2, 3, 3), details = c("age", "gender", "age", "gender", "age", "gender"), values = c(25, "M", 30, "F", 28, "M")) # Using pivot_wider to spread 'details' and 'values' columns while keeping 'id' column in long format wide_df <- df %>% pivot_wider(names_from = details, values_from = values) # Print the resultant dataframe print(wide_df) 441 chars13 lines
library(tidyr) # Example dataframe df <- data.frame(id = c(1, 1, 2, 2, 3, 3), details = c("age", "gender", "age", "gender", "age", "gender"), values = c(25, "M", 30, "F", 28, "M")) # Using pivot_wider to spread 'details' and 'values' columns while keeping 'id' column in long format wide_df <- df %>% pivot_wider(names_from = details, values_from = values) # Print the resultant dataframe print(wide_df)
gistlibby LogSnag