Reading the data
...
- set the working directory using
setwd
and read the dataset into R and assign it the variablesim.alspac
using theread.csv
function - Look up the
colnames
function in the help file and apply it tosim.alspac
to list all the column headings in the data. - Look up the
dim
function in the help file and apply it to tosim.alspac
to get the dimensions of the dataset. Number of columns is the number of variables, number of rows is the number of participants.
...
Subsetting and assigning data
Descriptive / summary stats in R
contingency table (a summary table of 3+ variables) gender, age, BMI
table( )
ftable( )
summary stats mean, min, max and quantiles
summary()
histogram - to identify types of distributions of a variable
hist()
box and whisker plot summarizes graphically the min, max, 25-75 percentiles
boxplot()
Rounding numbers
signif(x, digits = 6)
# set how many significant figures using digits =
or use
format(round(x, 2), nsmall = 2)
# for two d.p
Adding text to graphs
text(70,12, labels=paste("y=", RegM11$coefficients[2], "+", RegM11$coefficients[1]), col="orange")