data.table - How to unquote string in R to access column in data table -
suppose have data.table called mysample. has multiple columns, 2 of them being 'weight' , height'. can access weight column typing: mysample[,weight]. when try write mysample[,colnames(mysample)[1]] cannot see elements of 'weight'. there wrong code?
please refer section 1.1 of data.table faq: http://cran.r-project.org/web/packages/data.table/vignettes/datatable-faq.pdf
colnames(mysample)[1] evaluates character vector "weight", , 2nd argument j in data.table expression evaluated within scope of dt. thus, "weight" evaluates character vector "weight" , can't see elements of "weight" column. subset "weight" column should try:
mysample[,colnames(mysample)[1], = f]
Comments
Post a Comment