How can I avoid NA
columns in dcast()
output from the reshape2
package?
In this dummy example the dcast()
o
Here is how I was able to get around it:
iris[is.na(iris)] <- 'None'
x <- dcast(iris, Species ~ Species2, value.var="Sepal.Width", fun.aggregate = length)
x$None <- NULL
The idea is that you replace all the NAs with 'None', so that dcast creates a column called 'None' rather than 'NA'. Then, you can just delete that column in the next step if you don't need it.