Is there a specific R function that i can use to achieve the following? I tried using gather, but its not quite the same.
df3 <-data.frame(ID=c(1,1,2,2), ID2= c(11,11,22,21), ID3=c(22,22,33,33), b =c(5,0,0,0), c=c(0,0, 3,0), d=c(0L,3,0,4))
df3
# ID ID2 ID3 b c d
#1 1 11 22 5 0 0
#2 1 11 22 0 0 3
#3 2 22 33 0 3 0
#4 2 21 33 0 0 4
after_df3 <- data.frame(ID1=c(1,2,2), ID2=c(11,22,21), ID3=c(22,33,33), b=c(5,0,0), c=c(0,3,0), d=c(3,0,4))
after_df3
# ID1 ID2 ID3 b c d
#1 1 11 22 5 0 3
#2 2 22 33 0 3 0
#3 2 21 33 0 0 4