[R] Converting a data frame with values into a matrix/

hadley wickham h.wickham at gmail.com
Wed Mar 12 19:26:48 CET 2008


>  mm1  <- cast(mm, Class~Name)
>  aba <- mm1[,2:6]
>  aba[is.na(aba)] <- 1
>  final <- data.frame(mm1$Class, aba)
>  names(final) <- names(mm1)
>  final

You can abbreviate all this to:

final <- cast(mm, Class ~ Name, fill = 1)

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list