melt in data.table in r -


so working in r using data table , there 5000 observations. have developed these new grade variables own categories (ex. grade1, grade2, grade3,etc) , want combine them 1 variable called grade. have used command:

dt.m1 = melt(    mathsummary,    id.vars = c("date", "total.events", "unique.events"),    measure.vars = c("gradeprek", "grade1", "grade2", "grade3", "grade4",                                  "grade5", "grade6", "grade7", "grade8",                                  "algebra1", "algebra2", "geometry", "precalculus"),    value.factor=true, na.rm=true ) 

however, when results came, gave me 65000 observations. perhaps may have created duplicates or something. penny thoughts?

i think code correct , not understanding how melt works. melt turns data long-format , looks code working, have 13 variables , 5000 observations, when turned long format, 13 * 5000 = 65000 observations.

however, in long format, row should not thought of single observation, instead single measure instance. in long format, notice melted data.table produced like.

date total.events unique.events variable value

and each unique combination of 3 measures, have thirteen rows, , each row variable - value pair.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -