Getting to Know R
Getting ready for the course
Download
Intro_to_R.tar
fromhttps://ki-data.mit.edu/bcc/teaching/Intro_to_R/
onto Desktop.Un-compress
Intro_to_R.tar
to a folder "Intro_to_R"Open RStudio
Under the File menu, click on New project, choose Existing Directory
Use Browse to locate to the "Intro_to_R" folder and then Create Project This will be your working directory for the rest of the day (e.g. ~/Desktop/Intro_to_R)
Create a new R script (File > New File > R script) and save it in your working directory (e.g. intro_to_R.R). Here, you can type all the commands we run during the course, and save it for later reference.
Using R as a calculator
> 1+2
[1] 3
> 1+2*3+4*5
[1] 27
R is good at statistics
> group1<-c(4.5,4.7,4.2,4.8,3.9)
> group2<-c(6.0,5.9,5.8,5.5,6.2)
> t.test(group1,group2)
Welch Two Sample t-test
data: group1 and group2
t = -7.2281, df = 7.1573, p-value = 0.0001556
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-1.9355112 -0.9844888
sample estimates:
mean of x mean of y
4.42 5.88
The R syntax from an example script
# Load libraries
library(Biobase)
library(limma)
library(ggplot2)
# Setup directory variables
baseDir <- getwd()
dataDir <- file.path(baseDir, "data")
# Load data
design_dat <- read.table(file.path(dataDir, 'mouse_exp_design.csv'), header=T, sep=",", row.names=1)
*The above snippet of R code has many different “parts of speech” for R (syntax):
*the comments # and how they are used to document function and its content
*the assignment operator <-
*variables and functions
*the = for arguments for functions
Last updated
Was this helpful?