I was trying to calculate the following sum in R and I get stuck because I can't find the right sum function in R. Any help will be appreciated.
Sum(i, {i,1,10})
The pseudo code for this can be as follows:
for(i=1;i<=10;i++)
sum=i;
I was trying to calculate the following sum in R and I get stuck because I can't find the right sum function in R. Any help will be appreciated.
Sum(i, {i,1,10})
The pseudo code for this can be as follows:
for(i=1;i<=10;i++)
sum=i;
You should check out the docs (?sum
in RStudio) but here are some things you can do with sum
mynumbers <- c(1:5, 13, 17, pi, factorial(5))
sum(mynumbers)
#[1] 168.1416
mynumbers2 <- c(1:5, 13, 17, NA, NA, pi, factorial(5))
sum(mynumbers2, na.rm = TRUE)
#[1] 168.1416
Maybe this could help:
sum(1:10)