I have a data.table called client
, that has the following columns:
"location" "clientID" "gender" "age" "startYear" "ag1" "ag2"
There is the age
variable and two factorised versions of it: ag1
and ag2
.
Now i want to group my data, using the ag1
factorization:
agegroup <- sym(agegroup)
clientTotal <- client[,.(NOinsureds=length(clientID)), by = .(gender, agegroup, startYear)]
which results in an error:
Show in New WindowClear OutputExpand/Collapse Output Error in
[.data.table(clientData, , .(NOinsureds = length(clientID)), : column or expression 2 of 'by' or 'keyby' is type symbol. Do not quote column names. Usage: DT[,sum(colC),by=list(colA,month(colB))]
I assume this is because the NSE
. I have read a little about it online, which is why i included agegroup <- sym(agegroup)
, but it does not seem to work.
Any suggestions?
I will be manipulating the data quite a lot, and i will also be writing functions, so maybe keep that in mind when recommending solutions :)