I want to modify my data frame in R. My current data frame is:
df <- data.frame(ID = c(1, 2, 3), A = c(10, 20, 30), B = c(0, 0, 1))
df_transposed <- df %>% pivot_longer(cols = -ID, names_to = "Variable", values_to = "Value") %>% pivot_wider(names_from = ID, values_from = Value)
I need modify my data frame to the follow form:
row A X1_cen B X2_cen ....
X1 10 0 11 1
X2 12 0 13 0
I need the code in R to modify my dataframe. The packages and more :)