I need to collapse "+/-" columns names into one column name and add counts. Here is an example of the dataset.
data <- as.data.frame(c("+A","-A","+A","-A", "+A","+A","-B","+B","-B", "C","C"))
colnames(data) <- "class"
table(data$class)
-A -B +A +B C
2 2 4 1 2
I would like to collapse those -/+ col names into no sign column names and add them up.
The desired dataset should look like below:
A B C
6 3 2
Sometimes these +/- variables might be missing or category "C" might be missing too. How can I add them up even though I have some missing categories?
Any thoughts?