Skip to content
Prev 256816 / 398506 Next

Hash table...

On Thu, Apr 14, 2011 at 06:44:53PM +1200, Worik R wrote:
If y is an integer, factor or string you could try something along these
lines:

cache <- list()
y <- 12
cache[[as.character(y)]] <- sqrt(y)
y<-98
cache[[as.character(y)]] <- sqrt(y)
cache

$`12`
[1] 3.464102

$`98`
[1] 9.899495

Of course this can get you in trouble if y is a floating point
number because of the issues with "identity" of such numbers, as
discussed in ?all.equal and FAQ 7.31 "Why doesn't R think these
numbers are equal?".

cu
	Philipp