You can also upgrade to R-devel or to R 3.1.0 due out in a month or so
-- those will run this code much more efficiently.

Using setattr is OK if you really know what you are doing, but if you
are not careful using it can modify objects you do not intend to
modify.

Best,

luke

On Tue, 11 Mar 2014, Smart Guy wrote:

Apologies for the late reply. I was out on vacation.
I tried setattr() from data.table package and it worked like a magic.

Thanks a lot for the help. setattr() is really faster than "attributes".

Regards,
SG


On 22 February 2014 12:29, Philippe Grosjean <phgrosj...@sciviews.org>wrote:

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.







--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
   Actuarial Science
241 Schaeffer Hall                  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
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.

Reply via email to