I have a data frame which is mostly zeros (sparse data frame?) something similar to
name,factor_1,factor_2,factor_3
ABC,1,0,0
DEF,0,1,0
GHI,0,0,1
The actual data is about 90,000 rows with 10,000 features. Can I convert this to a sparse matrix? I am expecting to gain time and space efficiencies by utilizing a sparse matrix instead of a data frame.
Any help would be appreciated
Update #1: Here is some code to generate the data frame. Thanks Richard for providing this
x <- structure(list(name = structure(1:3, .Label = c("ABC", "DEF", "GHI"),
class = "factor"),
factor_1 = c(1L, 0L, 0L),
factor_2 = c(0L,1L, 0L),
factor_3 = c(0L, 0L, 1L)),
.Names = c("name", "factor_1","factor_2", "factor_3"),
class = "data.frame",
row.names = c(NA,-3L))
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…