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


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

Reply via email to