Chapter 2 – Let’s get our hands dirty

A couple of notes  before I start:

The last tutorial was an introduction. This one and everyone from now on will try and follow one simple structure. There will be a goal on what we learn at the end of it. Every subsequent chapter will probably build on what we’ve learned before.

Please type and not just read these. Even if seems like you can understand it – which it mostly will. Refrain from the temptation to just read. Just start typing these commands into your screen. You will go much beyond beyond these tutorials if you teach yourself by typing and becoming familiar with the syntax. Can’t stress enough on this.

Goal of this chapter:

Create a simple data set of multiples of 3 starting from 30 – 120. Explore some basic statistical properties mean, variance, standard deviation and variance of this data set. You will be exploring basic properties a lot if you’re working with data. Useful to know.

Open R

Type the following commands:

#Start typing. Do not read!Including these comments.

#This is a way to comment out code
pi
print(“Why am I typing this?”)
print(“Probbly to learn something”)
print(“Let’s try printing two sentences now.”);print(“Here you go.”)
cat(“This is a way of joining stuff”,”here you go”)
c<-3
c^2
cat(“Use it with variables as well”;c)
d<-4
print (c+d)
ls()
rm(d)
# Now to create small data sets
x<-c(1,2,3,4,56)
mean(x)
median(x)
sd(x)
var(x)

summary(x)
y<-log(x+1)
x+y
x*y
#Stop here. Notice how different it is from traditional matrix multiplication.
cor(x,y)
#Stop here.Look up correlation if you do not know it.
#Now we’re getting closer to the goal
0:9
10:19
seq(from=1, to=15, by=3)
rep(pi, times=5)
#Stop here. You should be able to solve the goal.

Take the above code – copy paste it into an editor and write a comment before the start of each line explaining what it does. Use help() if required.

Additional fun –

We introduced an important concept of correlation. Watch this video from the Khan Academy just to never confuse it causation.

Feedback? Send it romymisra [at] gmail.com or in the comments.

 

Leave a Reply

Your email address will not be published.