reshape2's dcast() Adds NAs to Data Frame
Can you provide a reproducible example? See, e.g., http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for information on how to do so. My entirely unjustified guess is that the NAs appear for combinations of factor levels that don't exist. Michael
On Tue, Aug 7, 2012 at 4:45 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
I need to understand how and why dcast() adds NAs to a data frame that contained no missing values. The database table of chemical concentrations has all missing values removed because they cannot contribute to data analyses. The structure of the R data frame of these data have no NA values, and neither does the data frame resulting from applying the reshape2 melt() function to it. However, the data frame produced by the dcast() function does contain NAs for all chemicals. I assume this is because of the syntax I used: chem.cast <- dcast(chem.melt, site + sampdate + era + ceneq1 + floor + ceiling ~ param) How should I reshape the data frame from long to wide without adding these spurious NAs? Rich
______________________________________________ R-help at 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.