I am trying to remove a group of columns from a data frame (followed this) but I get an error in return.
Specifically, size of the data frame (NNF.data) is 34233 rows with 147 columns:
[118] "NNF.2015.03.EUR" "NNF.2015.04.EUR" "NNF.2015.05.EUR"
[121] "NNF.2015.06.EUR" "NNF.2015.07.EUR" "NNF.2015.08.EUR"
[124] "NNF.2015.09.EUR" "NNF.2015.10.EUR" "NNF.2015.11.EUR"
[127] "NNF.2015.12.EUR" "NNF.2016.01.EUR" "NNF.2016.02.EUR"
[130] "NNF.2016.03.EUR" "NNF.2016.04.EUR" "NNF.2016.05.EUR"
[133] "NNF.2016.06.EUR" "NNF.2016.07.EUR" "NNF.2016.08.EUR"
[136] "YTD.NNF.Year2005.EUR" "YTD.NNF.Year2006.EUR" "YTD.NNF.Year2007.EUR"
[139] "YTD.NNF.Year2008.EUR" "YTD.NNF.Year2009.EUR" "YTD.NNF.Year2010.EUR"
[142] "YTD.NNF.Year2011.EUR" "YTD.NNF.Year2012.EUR" "YTD.NNF.Year2013.EUR"
[145] "YTD.NNF.Year2014.EUR" "YTD.NNF.Year2015.EUR" "YTD.NNF.Year2016.EUR"
What I want to do is to remove the columns from 136-147, or the ones that contain YTD in their name.
I tried to use
NNF.data[, grep("YTD", names(NNF.data)):= NULL]
but I get the error:
Error in `[.data.frame`(NNF.data, , `:=`(grep("YTD", names(NNF.data)), :
could not find function ":="
Similarly, I tried
NNF.data[, which(grepl("YTD", colnames(NNF.data))):=NULL]
but again, I get
Error in `[.data.frame`(NNF.data, , `:=`(which(grepl("YTD", colnames(NNF.data))), :
could not find function ":="
Any suggestions please? I made sure that NNF.data is a data frame
> is.data.frame(NNF.data)
[1] TRUE