[R] some R exercises
Florian Weiler
fweiler08 at jhubc.it
Wed May 9 13:26:39 CEST 2012
On Exercise 5, how about this (I'm rather new to R as well, so no guarantee
this is right and I'm sure there are more efficient ways to do this!):
fun1 <- function(x) {
y <- 0
for (i in 1:length(x))
{y[i] <- (x[i]-mean(x))^2}
sum(y)/(length(x)+1)
}
fun2 <- function(x) {
y <- 0
for (i in 1:length(x))
{y[i] <- (x[i]-mean(x))^2}
sum(y)/(length(x))
}
x <- rexp(15)
fun1(x)
fun2(x)
--
View this message in context: http://r.789695.n4.nabble.com/some-R-exercises-tp4619850p4620143.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list