-2

I do have a question regarding my data format that I didn't find in any of the posts here.

Currently, I have a dataframe that looks like this:

> bymonth
       month n_positive n_negative 
1      April        563        587
2     August        186        240
3   December        671        581
4   February       2026       1827
5    January       1227       1115
6       July         63         57
7       June        360        336
8      March        430        378
9        May        422        481
10  November       1017        947
11   October        617        694
12 September        601        434

I would like to create a time series with the month names as variables. Something that looks like this:

> bymonth
   sentiment    January   February    March   April  ...
1 n_positive       1227       2026      430     563  ...
2 n_negative       1115       1827      378     587  ...

How can I do this? Any help would be very much appreciated!

user2554330
  • 37,248
  • 4
  • 43
  • 90
Consuello
  • 1
  • 2

1 Answers1

2

You just want to transpose your data?

t(bymonth)
AidanGawronski
  • 2,055
  • 1
  • 14
  • 24
  • Correct, I would add a couple of lines to turn the result into data.frame with correct col names, sentiment column etc... e.g. : `m=as.data.frame(t(DF[,-1]));colnames(m)=DF$month;m=cbind(sentiment=row.names(m),m)` – digEmAll Feb 23 '18 at 13:57
  • Thanks guys! That helped a lot! – Consuello Feb 23 '18 at 14:09