Skip to content

Instantly share code, notes, and snippets.

@mocon
Last active September 20, 2017 05:17
Show Gist options
  • Save mocon/a12f955410678ec39e5bf827251a302e to your computer and use it in GitHub Desktop.
Save mocon/a12f955410678ec39e5bf827251a302e to your computer and use it in GitHub Desktop.
Learning some R

Lab 1

# Clear console
cat("\014")

(5/9)*(52.7-32)
2^3
2**3
pi*6^2
log10(1000)
log(3.8)
exp(1.335)

Molar <- c(2.6,7.2,2.9,6.7,4.8,3.8,5.3,5.1, 
           + 7.9,7.3,3.7,8.9,8.4,6,5.2,9.6,4.5,4.8,7.3,
           + 4.8,3.3,6.8,4.5,8.6)

summary(Molar)
par(mai=c(1.3,1.5,1,1))
hist(Molar,
     breaks=seq(2.5,10.5,by=1),
     xlab="Length in mm",
     main="Molar length of 24 Acropithecus rigidus",
     cex.main=3,cex.axis=2.7,cex.lab=2.7)

Creating a frequency distribution table

# Clear console
cat("\014")

# Frequency table
f.breaks <- factor(cut(Molar, breaks = seq(2.5,10.5,by = 1)))
f.table <- as.data.frame(table(f.breaks))
f.table <-transform(f.table, relative = round(prop.table(Freq),3))
f.table

Creating a fan plot

# Clear console
cat("\014")

# Fan plot
counts <-c(3,4,6,1,5,2,2,1)
sum <-sum(counts)
rf <- counts/sum
round(rf,3)
slice <-c("[2.5-3.5]", "(3.5-4.5]", "(4.5-5.5]", "(5.5-6.5]", "(6.5-7.5]", "(7.5-8.5]", "(8.5-9.5]", "(9.5-10.5]")
pct <-round(counts/sum*100,1)
crust <-paste(slice,":",pct,"%",sep = " ")
par(mai=c(1.2,1.5,1,0.3))
fan.plot(counts,labels=crust,label.radius = c(1.15,1.1,1.1,1.1,1.1,1.1,1.1,1.1),main = "Molar Length of 24 Acropithecus rigidus in mm")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment