From jacobson@mail.cs.uni.edu Tue Aug 25 14:47:40 2015 Date: Tue, 25 Aug 2015 14:47:37 -0500 From: jacobson@mail.cs.uni.edu To: jacobson@cs.uni.edu Subject: Floor and Ceiling and RStudio and R functions [ The following text is in the "iso-8859-1" character set. ] [ Your display is set for the "ISO-8859-15" character set. ] [ Some special characters may be displayed incorrectly. ] 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) ) } floorEm <- function( a ) { for (x in a) { x <- floor(x) } return( a ) }