I have a data frame that has 7 rows and 156 variables. One of the columns is the Date column and the other columns are names of countries that have total number of installs for each of the seven days. It looks something like this:
Dates USA Argentina France...
06/01/2020 3 6 1
06/02/2020 2 4 6
. . . .
. . . .
I wanted to use melt()
from reshape2
to get it into long format so I typed the following code
dfnames<-names(df)[-1] #I don't want the variable Dates to be included
df<-melt(df, id.vars = dfnames, variable.name = "country", value.name ="installs")
instead of getting something that looked like this
Dates country installs
06/01/2020 USA 3
06/02/2020 USA 2
.
.
06/01/2020 Argentina 6
06/01/2020 Argentina 4
.
.
etc
I get the same data frame where nothing has changed except that the Dates column is gone and that there are the columns country and installs added on with country having 7 entries of the word Dates and installs the actual dates.