Skip to content
Advertisement

Dataframe transformation (preparation to sql export)

How to make such transformation as in the below image ? enter image description here

Advertisement

Answer

You can use the gather function form the tidyr package:

library(tidyr)

client1 <- c(23, 12, NA)
client2 <- c(45, 34, 56)
df1 <- data.frame(client1, client2)
df2 <- gather(df1, key = "Clients", value = "Money", na.rm = TRUE)
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement