I have multiple data tables that have many rows of student data such that the same student can be on several rows with minor differences in some columns, ie:
FirstName LastName HS Uni Semester Graduated
-Suzy Heddenbocher CHS BigU 1 N
-Suzy Heddenbocher CHS BigU 2 N
-Ed Heddenbocher NHS SWSt 1 N
I ordered the data table with setkey(Y1, LastName, FirstName)
and then tried to set uniqid
by using
Y1[, uniqid:=.GRP, by=key(Y1)]
I get consistent errors:
Error in [.data.table(Y1, , :=(uniqid, .GRP), by = key(Y1)) : Type of RHS ('integer') must match LHS ('double'). To check and coerce would impact performance too much for the fastest cases. Either change the type of the target column, or coerce the RHS of := yourself (e.g. by using 1L instead of 1)
NB: Thank you for your help. I had no idea what a "double precision" vector was until you told me that was what "double" meant, but it was a column class issue. I solved the problem by running this code:
setkey(Y3, "Last Name", "First Name")
Y3$uniqid <- as.integer(Y3$uniqid)
Y3[, uniqid:=.GRP, by=key(Y3)]