R is a programming language originally designed by statisticians. Now it is a common programming language for scientific applications.
In this course we will use R through the RStudio interface. Your instructor will demonstrate how to access and log into the RStudio server for this class.
version##                _                           
## platform       x86_64-pc-linux-gnu         
## arch           x86_64                      
## os             linux-gnu                   
## system         x86_64, linux-gnu           
## status                                     
## major          3                           
## minor          6.1                         
## year           2019                        
## month          07                          
## day            05                          
## svn rev        76782                       
## language       R                           
## version.string R version 3.6.1 (2019-07-05)
## nickname       Action of the Toes
We can now get started with the R command promp open.
x=2
print(x) ##Print method## [1] 2
class(x)## [1] "numeric"
x=seq(1:10) # Create a vector
class(x)## [1] "integer"
print(x)##  [1]  1  2  3  4  5  6  7  8  9 10
print(x[1]) # First index of vector## [1] 1
print(x[1:5])## [1] 1 2 3 4 5
y = matrix(nrow=5, ncol=5) # create a 5x5 matrix
print(y)##      [,1] [,2] [,3] [,4] [,5]
## [1,]   NA   NA   NA   NA   NA
## [2,]   NA   NA   NA   NA   NA
## [3,]   NA   NA   NA   NA   NA
## [4,]   NA   NA   NA   NA   NA
## [5,]   NA   NA   NA   NA   NA
class(y)## [1] "matrix"
y[1,1] = 5
print(y)##      [,1] [,2] [,3] [,4] [,5]
## [1,]    5   NA   NA   NA   NA
## [2,]   NA   NA   NA   NA   NA
## [3,]   NA   NA   NA   NA   NA
## [4,]   NA   NA   NA   NA   NA
## [5,]   NA   NA   NA   NA   NA
y[,1]= x[1:5]
print(y)##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1   NA   NA   NA   NA
## [2,]    2   NA   NA   NA   NA
## [3,]    3   NA   NA   NA   NA
## [4,]    4   NA   NA   NA   NA
## [5,]    5   NA   NA   NA   NA
class(y[,1])## [1] "numeric"
y = cbind(seq(1:5), 
seq(1:5),
seq(1:5),
seq(1:5),
seq(1:5))
class(y)## [1] "matrix"
read.table() read.csv() read.delim()
cars = read.table('https://raw.githubusercontent.com/rsh249/bioinformatics/master/data/mtcars.csv', header=T, sep = ',') # Read a comma separated values file
head(cars)cars = read.csv('https://raw.githubusercontent.com/rsh249/bioinformatics/master/data/mtcars.csv')
cars = read.delim('https://raw.githubusercontent.com/rsh249/bioinformatics/master/data/mtcars.csv', sep=',')write.table(cars, file='mtcars.tab')
write.csv(cars, file='mtcars.csv')Where are these files now?