Write your first R code

Rstats

A short tutorial to write your first R code

Binod Jung Bogati true
10-15-2018

Running code in R is easy (if copy/paste). Our motive here is not to teach you R. However, you’ll catch with basic R code in no-time.

Run the code below:

# printing
print("Hello World")
# assignment
a <- 10
b <- 15
# add
a + b
# add + assign
c <- a + b
# print 1 to 100
1:10
# sum from 1 to 100
sum(1:100)
# mean / average
mean(c(10, 15, 20, 25))
# median / central value
median(c(5, 10, 15, 25, 30))
# square root
sqrt(64)
# function
addition <- function(x, y){
x + y
}
# calling function
addition(10, 15)