I have a .csv file I have imported to R, I need to convert the Data to Long format, where varying will be date from 4/1/1996 to 12/16/2017. The data has been stored in R, where the variables are RegionName, State, the sizerank and the different Dates which the observation was made for each Region in each State. Of course, the Idvar, will be the SizeRank:
Asked
Active
Viewed 631 times
0
-
have a look at the `tidyr` package and the function `gather` therein. This does what you want. – Wolfgang Feb 22 '17 at 09:46
-
What about using the reshape(), function? – sigma Feb 22 '17 at 09:48
-
@akrun, don't really think that this is a duplicate of the one you've linked to as this is clearly R related and the other one is about bash. – takje Feb 22 '17 at 16:10
-
@takje Reopened the post – akrun Feb 22 '17 at 16:13
-
@akrun, it is a duplicate question however. Posted the r-specific link in an earlier comment without mentioning you. – takje Feb 22 '17 at 16:15
1 Answers
2
library(data.table)
dt <- fread("file.csv")
melt(dt, id.vars = c("RegionName", "State", "SizeRank"), variable.name = "date")
I think this does what you want.

wligtenberg
- 7,695
- 3
- 22
- 28