tags:

views:

58

answers:

2

I'd like to melt the dataframe so that in one column i have dates in a second i have username as the variable and finally the value.

I'm getting this error:

Error in as.Date.numeric(value) : 'origin' must be supplied

and while I understand the error I'm not exactly sure how to get around it.

A small sample of the data is:

structure(list(created_at = structure(c(14007, 14008, 14009, 
14010, 14011, 14012), class = "Date"), benjamin = c(16, 0, 0, 
0, 0, 0), byron = c(0, 0, 0, 0, 0, 0), cameronc = c(0, 0, 0, 
0, 0, 0), daniel = c(0, 0, 0, 0, 0, 0), djdiaz = c(0, 0, 0, 0, 
0, 0), gene = c(16, 77, 64, 38, 72, 36), joel = c(0, 0, 0, 0, 
0, 2), kerem = c(0, 0, 0, 0, 0, 0), sophia = c(0, 0, 0, 0, 0, 
0), SuperMoonMan = c(0, 0, 0, 0, 0, 0)), .Names = c("created_at", 
"benjamin", "byron", "cameronc", "daniel", "djdiaz", "gene", 
"joel", "kerem", "sophia", "SuperMoonMan"), row.names = c(NA, 
6L), class = c("cast_df", "data.frame"))

Thanks for your help.

+2  A: 

Try converting the 'created_at' variable into a character vector. 'melt' also doesn't seem to like the 'cast_df' class, but I had success by resetting the class to just 'data.frame'. Like so:

df <- as.data.frame(df)
df$created_at <- as.character(df$created_at)
library(reshape)
melt(df)
wkmor1
i'm giving wkmor1 the check mark because he got it first and did solve the problem. That said Marek big thanks for helping me better wrap my head around what was going on.
Dan
+1  A: 

You error is caused by rbind used in melt, which is consequence of wrong data to melt. I don't know how you create your cast_df data.frame, but it missing attributes (idvars and rdimnames) which are required by melt.cast_df.

That is why wkmor1 solution works, melt.data.frame don't need this arguments. And without converting Date to character it can be done as:

df <- as.data.frame(df)
melt(df, id="created_at")
Marek