Skip to content

Instantly share code, notes, and snippets.

@gangchen
Created December 14, 2012 05:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gangchen/4282933 to your computer and use it in GitHub Desktop.
Save gangchen/4282933 to your computer and use it in GitHub Desktop.
Simple samples for R lesson
# Examples for R training
# Author: Gang Chen <chengang@genomics.cn>
# Nov 2012
# Lesson 2
# vector
a <- c(1, 2, 5, 3, 6, -2, 4)
b <- c("one", "two", "three")
c <- c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE)
# matrix
y <- matrix(1:20, nrow=5, ncol=4)
x <- matrix(1:10, nrow=2)
# array
myarray <- array(vector, dimensions, dimnames)
# data frame
patientID <- c(1, 2, 3, 4)
age <- c(25, 34, 28, 52)
diabetes <- c("Type1", "Type2", "Type1", "Type1")
status <- c("Poor", "Improved", "Excellent", "Poor")
patientdata <- data.frame(patientID, age, diabetes, status)
# factor
diabetes = factor(diabetes)
# list
g <- "My First List"
h <- c(25, 26, 18, 39)
j <- matrix(1:10, nrow=5)
k <- c("one", "two", "three")
mylist <- list(title=g, ages=h, j, k)
# Lesson 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment