[R] Slow update(insert) on Data.frame
Charles C. Berry
cberry at tajo.ucsd.edu
Tue Nov 23 17:18:11 CET 2010
On Tue, 23 Nov 2010, Joel wrote:
>
> Hi
>
> When I try to update an number in a large data.frame by its pos It's really
> slow it take almost a sec to do this and I wonder why and if where is any
> faster way to update a number in a data.frame
>
> ive tried
>
> DF$col[POS]<-number
> DF[xPOS,yPOS]<-number
See
?tracemem
then try
tracemem( DF )
DF$col[POS]<-number
DF[xPOS,yPOS]<-number
then
mat <- as.matrix( DF )
tracemem( mat )
mat[ 2,3 ] <- 4
mat[ 15 ] <- 5
If your data.frame can be represented by a matrix, a single update will
likely be faster as it can be done without making any copies.
If you are doing more than one update, it will help to do them all at
once. Reread
?Subscript
and section 5.2 and 5.3 of Intro to R if you are unsure how to do that.
HTH,
Chuck
>
> Thx
> //Joel
> --
> View this message in context: http://r.789695.n4.nabble.com/Slow-update-insert-on-Data-frame-tp3055707p3055707.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>
Charles C. Berry Dept of Family/Preventive Medicine
cberry at tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
More information about the R-help
mailing list