Skip to content
Prev 278879 / 398502 Next

Replacing a value in a dataframe

On 30.11.2011 12:26, Bert Gunter wrote:
Sure, thanks.
Well, just profile it. The latter has some overhead, of course:

  d <- data.frame(a=c(TRUE, FALSE))
  system.time(for(i in 1:1e4) {d <- data.frame(a=c(TRUE, FALSE)); d$a <- 
as.integer(d$a)})
  system.time(for(i in 1:1e4) {d <- data.frame(a=c(TRUE, FALSE)); d <- 
within(d, a <- as.integer(a))})


Uwe Ligges