I want to collapse my dataframe so that there's only one factor variable per row and the values all collapse on themselves to one row each. Here's an example:
mat <- data.frame(type = c(rep("int",5), rep("num",5)), diag(sample.int(9,6), 10))
mat[mat == 0] <- NA
mat[5,11] <- 4
Now I want this to be:
type, X1, ..., X8, X9, X10
int, 2, 7, ...,NA, NA, 4
num, NA, NA, ..., 3, 1
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…