I've successfully reformatted data frames from long to wide with reshape2, but this time I'm getting errors that I want to understand and resolve. Here's the data frame structure and the results of the melt() and dcast() functions:
str(waterchem) 'data.frame': 128412 obs. of 8 variables: $ site : Factor w/ 64 levels "D-1","D-2","D-3",..: 1 1 1 1 1 1 1 ... $ sampdate: Date, format: "2007-12-12" "2007-12-12" ... $ preeq0 : logi TRUE TRUE TRUE TRUE TRUE TRUE ... $ param : Factor w/ 37 levels "Ag","Al","Alk_tot",..: 1 2 8 17 3 4 ... $ quant : num 0.005 0.106 1 231 231 0.011 0.001 0.002 0.001 100 ... $ ceneq1 : logi TRUE FALSE TRUE FALSE FALSE FALSE ... $ floor : num 0 0.106 0 231 231 0.011 0 0 0 100 ... $ ceiling : num 0.005 0.106 1 231 231 0.011 0.001 0.002 0.001 100 ...
chem.melt <- melt(waterchem, idvars = c('site', 'sampdate', 'preeq0', 'param', 'ceneq1', 'floor', 'ceiling'))
Using site, preeq0, param, ceneq1 as id variables
chem.cast <- dcast(chem.melt, site + sampdate + preeq0 + ceneq1 + floor + ceiling ~ param)
Error in eval(expr, envir, enclos) : object 'sampdate' not found Because these data have some censored data there is the logical indicator (ceneq1) to identify censored and uncensored values the the interval ends (floor and ceiling) for multiply censored values. One factor of analytical interest whether the sampdate is pre- or post-event; that uses the logical indicator preeq0. Please point out where my melt() and dcast() syntax was incorrect. I will provide more information if needed. TIA, Rich ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.