Hi all,
I need to change a dataframe that is has a variable arranged by date like this:
ID Var_Day1 Var_Day2 Var_Day3
1 2 66 222
2 5 55 333
3 6 44 555
4 3 33 444
5 4 22 333
into a new dataframe with one column for the variable for all days. Something like this:
ID Day Var
1 1 2
2 1 5
3 1 6
4 1 3
5 1 4
1 2 66
2 2 55
3 2 44
4 2 33
5 2 22
1 3 222
2 3 333
3 3 555
4 3 444
5 3 333
I tried the package reshape and function melt but I’m stuck. Here is my code:
install.packages("reshape")
library ("reshape")
data<-read.csv("data by day.csv",header=T)
newdata <- melt(data, id=c("id"))
Any suggestion?
Many thanks,
Diego
I need to change a dataframe that is has a variable arranged by date like this:
ID Var_Day1 Var_Day2 Var_Day3
1 2 66 222
2 5 55 333
3 6 44 555
4 3 33 444
5 4 22 333
into a new dataframe with one column for the variable for all days. Something like this:
ID Day Var
1 1 2
2 1 5
3 1 6
4 1 3
5 1 4
1 2 66
2 2 55
3 2 44
4 2 33
5 2 22
1 3 222
2 3 333
3 3 555
4 3 444
5 3 333
I tried the package reshape and function melt but I’m stuck. Here is my code:
install.packages("reshape")
library ("reshape")
data<-read.csv("data by day.csv",header=T)
newdata <- melt(data, id=c("id"))
Any suggestion?
Many thanks,
Diego