Today, we are going to do some simple operations using R Studio and R. Then we will publish these through R Markdown to RPubs.
require(psych)
## Loading required package: psych
x=c(1,3,5,7,9)
y=seq(1,9, by=2) #seq = sequence
x
## [1] 1 3 5 7 9
y
## [1] 1 3 5 7 9
1/x
## [1] 1.0000000 0.3333333 0.2000000 0.1428571 0.1111111
1/y
## [1] 1.0000000 0.3333333 0.2000000 0.1428571 0.1111111
x+y
## [1] 2 6 10 14 18
x*y
## [1] 1 9 25 49 81
t(x)%*%y #t = transpose, what does this do?
## [,1]
## [1,] 165
Now, we go to the second slide.
z = c(1:3,NA)
z
## [1] 1 2 3 NA
ind=is.na(z)
ind
## [1] FALSE FALSE FALSE TRUE
q=z[!is.na(z)]
q
## [1] 1 2 3
typos = c(2,3,0,3,1,0,0,1)
mu=mean(typos)
M=median(typos)
s=sd(typos)
mybasicstats=c(mu,M,s)
names(mybasicstats)=c("mu","M", "s")
mybasicstats
## mu M s
## 1.25000 1.00000 1.28174
#loaded the pscyh library which contains "describe"
mydescribe=describe(typos)
mydescribe
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 8 1.25 1.28 1 1.25 1.48 0 3 3 0.31 -1.78 0.45
which.min(typos)
## [1] 3
which.max(typos)
## [1] 2