2*3; 2/2; 2^2
x=2
x*3;x/x;x^x
sqrt(1);exp(2)
#creating a vector
x<-c(3,1,9)
x
mean(x);sum(x)
x<-c(3,1,9)
y<-c(2,5,6)
x+y
#print 2nd element
x[2]


my.first.function= function(x){
    return(x^2)}

#call the function
my.first.function(2)


pyth= function(a,b){c = sqrt(a^2+b^2)
                   return(c)}
#call the function
pyth(3,4)


#modulo operator %%
3%%2;2%%2


#return true if a value is even
is.even = function(x){
if (x%%2 == 0) {return(TRUE)}

if (x%% ! 0){return(FALSE)}
              }
is.even(31)
is.even(44)

x = rep(NA,10)
for (i in 1:10) {x[i]=i}
    x

#while loop
#initialize i
i = 0
#the condition is that i < 0
while(i<10){i = i +1}
i

x = 1:3
sum(x); mean(x);sd(x)

unique(x)
length(x)

X = rnorm(10)
length(X[X<0])

sample(1:5)
sample(1:5,3)
sample(1:5,7, replace= TRUE)
sample(1:5,7, replace= TRUE, prob = c(.3,.3,.3,.1,0))
4.7:8.7
seq(from = 1,to = 10, by =1)
seq(from=20,to=30,length.out=30)
round(rnorm(1),2)
vector1=c(1,2,3)
sort(vector1)
sort(vector1,decreasing=TRUE)
rev(vector1)
x=1:5
x[x<2]
x[x>2&x<5]
X=rnorm(100)
Y=sapply(X,function(x)x^2)

factorial(5)/factorial(5-3)

integrate(dnorm, 0, 2)        

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: