R Basics - bcb420-2023/Jielin_Yang GitHub Wiki
- Review and practice basic R commands and functions
Time estimated: 3h, taken: 2h.
Start date: 2023-01-15, End date: 2023-01-15.
Some notes on the basic R commands and functions:
summary(object) # returns a named vector
summary(object)[index]
# define matrix
a <- c(1, 2, 3, 4, 5, 6)
dim(a) <- c(2, 3)
dim(a)
rbind()
cbind()
# Read to dataframe
read.table(file = ,
sep = "\t",
header = TRUE,
stringsAsFactors = FALSE)
# Iterate over a list and apply the function on all elements
lappy(someList, someFunction(x) {defineFunction})
# sort an object
order(someCollection)
# text matching
grep() # return vector of indices
grepl() # return vector of TRUE FASLE
# Built-in conditionals
all()
any()
exists() # whether an object exists
is.()
# Logical operations
x | y # vectorized
x & y
x || y # non-vectorized, coerce to the first Boolean operation
x && y
# Generics
methods(seq) # what specific methods does seq provide
getAnywhere(seq.default()) # Get the code of the default seq method
# Generic plots in R
plot()
pie()
hist()
stripchart()
stem()
barplot()
boxplot()
# Plotting
# Color palette in R defined by names can be found at
https://bcb420-2023.github.io/R_basics/r-plots.html#colours-by-name
# Lines
# argument lty for line type
# lwd for line width
# Plotting layout
par() # current plotting parameters
opar <- par(arguments) # set the plotting parameters
par(opar) # reset to default
# Task 23
begin <- 3
txt <- as.character()
while (begin >= 0) {
txt <- c(txt, as.character(begin))
begin <- begin - 1
}
txt <- c(txt, "Lift Off!")
txt
Steipe B. and Isserlin R. (2023) R - Basics. https://bcb420-2023.github.io/R_basics/index.html