You can use setattr() in the data.table package. It can be used too on data.frames or other objects. Best,
Philippe Grosjean On 22 Feb 2014, at 03:13, Smart Guy <smartgu...@gmail.com> wrote: > Hi All > > I am having problem running the 'attributes' command to set a attribute on > each column of a large dataset. Dataset has 80 columns and 312407 rows. Its > taking more than 60 seconds to set simple attributes like split=TRUE, > usermissing=FALSE. > > Here is the source code, assuming Dataset1 is the one that is large :- > > myfunction <- function() > { > cat("Before for loop:") > print(Sys.time()) > for( colIndex in 1 : 80) > { > cat("Before Attr", colIndex) > print(Sys.time()) > > attributes(Dataset1[1]) <- c(attributes(Dataset1[, colIndex]), list(coldesc > = c(), usermissing = c(FALSE), missingvalues = NULL, split = c(FALSE), > levelLabels = c(""))) > > cat("After Attr:") > print(Sys.time()) > } > cat("After for loop:") > print(Sys.time()) > } > > Its my feeling that R is passing all 312407 rows to set 'attributes' on a > cloumn. > > Is there a more efficent way to do this? > > > Thanks, > SG > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.