Skip to content

Instantly share code, notes, and snippets.

@aousabdo
Created December 30, 2014 19:03
Show Gist options
  • Select an option

  • Save aousabdo/20977bc773043c1836e0 to your computer and use it in GitHub Desktop.

Select an option

Save aousabdo/20977bc773043c1836e0 to your computer and use it in GitHub Desktop.
# start clean
rm(list=ls())
# load libraries
library(data.table)
DT <- data.table(A = rnorm(10), B = rnorm(10))
# this gives lots of warnings, there seems to be a better way of doing this
names(DT) <- tolower(names(DT))
# same with this line
names(DT) <- gsub(" ", ".", names(DT))
@aousabdo
Copy link
Author

updating data.table to dev version 1.9.5 fixes the problem.

@arunsrinivasan
Copy link

The error message says that it's better to use setnames() instead of names<-. This was meant for older versions of R which copied the entire data.frame/data.table to just replace names. Improvements were made in Rv3.1+. But still the idiomatic way would be to use setnames().

HTH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment