You are on page 1of 2

#intro.

r
2+3*log(252)#calculator
z<c(8,3,0,9,9,2,1,3)
z[4]#fourthelementofz
z[c(1,3,4)]#first,thirdandfourthelement
z[c(1,3,4)]#allexceptthefirst,thirdandfourth:
z[z<4]
z<4
which(z<4)#indicesofvaluesthatsatisfycondition
#basicoperations
length(z)#numberofelementsinz
sum(z)
sort(z)#sortinincreasingorder
#SORTING
#=========================================================
a=c(21,23,22,20)
ind=order(a)
d1=data.frame(a,ind)
#d2ind
#1214rownumberofthesmallest
#2231rownumberofthesecondsmallest
#3223
#4202rownumberofthelargest
#Columnnamesd2$d2d2$ind
d2=d1[ind,]#sorted
#aind
#4202
#1214
#3223
#2231

#datasetsavailableinRbase
#=========================================================
#googledatasetsinRbase,
#clickonstate.x77fordetails
head(state.x77)
class(state.x77)#[1]"matrix"
d0=data.frame(state.x77)
class(d0)#[1]"data.frame"
mean(d0$Income)
rownames(d0)
#sort
d1=d0[order(d0$Income),]#sortbyIncome
#sampling
ind=sample.int(50,10)
d2=d0[ind,]

You might also like