I have a data frame A
that I would like to melt row wise instead of column wise to look like B
(which also excludes observations with NA
in them). Can this be accomplished with the "melt" function?
A <- read.table(text=" Id1 Id2 Var1 Var2 Var3
1 1 1 2 NA
1 2 NA 3 4
1 3 5 6 7 ", header=T)
B <- read.table(text=" Id1 Id2 NewVar
1 1 1
1 1 2
1 2 3
1 2 4
1 3 5
1 3 6
1 3 7 ", header=T)
I found an answer to a similar question but the function seems like overkill and is beyond my current R skills.