-1
here my dataset
df=structure(list(id = c(1030879980L, 1030879990L), jan = c(170L, 
265L), feb = c(153L, 332L), march = c(170L, 290L), apr = c(1L, 
425L), may = c(66L, 406L), jume = c(125L, 352L), jul = c(129L, 
339L), aug = c(-109L, 470L), sept = c(56L, 486L), oct = c(37L, 
440L), nov = c(52L, 589L), dec = c(63L, 659L)), .Names = c("id", 
"jan", "feb", "march", "apr", "may", "jume", "jul", "aug", "sept", 
"oct", "nov", "dec"), class = "data.frame", row.names = c(NA, 
-2L))

How can I transpose it vertically to conduct time series analysis. There many obs. i can't do it manually. at the output i expect

id          month      value
1030879980  jan         507
1030879981  feb         502
1030879982  march       431
1030879983  apr 429
1030879984  may 449
1030879985  jume    368
1030879986  jul 406
1030879987  aug 290
1030879988  sept    309
1030879989  oct 371
1030879990  nov 481
1030879991  dec 536
1030879990  jan 265
1030879991  feb 332
1030879992  march   290
1030879993  apr 425
1030879994  may 406
1030879995  jume    352
1030879996  jul 339
1030879997  aug 470
1030879998  sept    486
1030879999  oct 440
1030880000  nov 589
1030880001  dec 659

How to perform it?

psysky
  • 3,037
  • 5
  • 28
  • 64

1 Answers1

1

You can use melt function from data.table or reshape2 packages:

library(data.table)
dt <- data.table(df)
dt.ts <- melt(dt, id.vars = "id", value.name = "value")
Bulat
  • 6,869
  • 1
  • 29
  • 52