oddcount <- function(x) { k <- 0 for (n in x) { if (n %% 2 == 1) k <- k+1 } return (k) } formals(oddcount) body(oddcount) ?log ?floor log2(1000) log2(64) log2(63) floor(log2(63)) ceiling(log2(63)) ll <- c(1:20) ll2 <- 2 * ll + 1 ll oddcount(ll) ll2 oddcount(ll2) factorial(ll) factorial(20) logSums <- function( x ) { fSum <- 0 # floor sum of logs to the base 2 lSum <- 0 # log to the base 2 sum cSum <- 0 # ceiling sum of logs to the base 2 for (i in x) { fSum <- fSum + floor(log2(i)) lSum <- lSum + log2(i) cSum <- cSum + ceiling(log2(i)) } return( c(fSum, lSum, cSum) ) }