[R] exponent function help??

mousy0815 mousy0815 at gmail.com
Wed Jul 13 03:23:40 CEST 2011


I'm trying to make a function that will output the exponent... so f2(2,2) = 4
and f2(2,3)=8. But I don't want to just use the x^n function, I want to do
it another way, and without a recursion. I did the follow code but for some
reason it doesn't work. Help please?


f2 <- function(x, n) #without recursion {
	y <- 1
	if (n==0) {return(1)} else {
	if (length(y) < (n+1) {
			y <-append(y, x, after = length(y))
		} else {return(prod(y))}
	
	}
}


--
View this message in context: http://r.789695.n4.nabble.com/exponent-function-help-tp3663943p3663943.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list