I have a data table with column headings as years, for example
head(gsdb_crossTab)
CONS_ID_URN 2010 2011 2012 2013 2014 2015 2016 2017
0TBX58 9 11 13 12 12 12 12 2
1 2 4 1 0 0 0 0 0
1000000 0 0 1 0 1 0 0 0
1000007 1 0 0 0 1 1 0 0
1000009 0 0 0 0 1 0 0 0
1000010 0 1 1 0 1 0 0 1
class(gsdb_crossTab)
[1] "data.table" "data.frame"
If I try and remove rows in column 2010 with a value of zero with
dummy=gsdb_crossTab["2010">0]
then I still find dummy contains rows in column 2010 with rows equal containing zeros.
However: if I rename the column using
setnames(gsdb_crossTab, "2010", "FRED")
and then perform the filter
gsdb_crossTab <- gsdb_crossTab[FRED>0]
then I get the result I expect.
My question is: please could somebody suggest a way to perform this operation without renaming the column to FRED i.e. using the column label "2010"?
Thank you,
Phil,