Created
December 14, 2012 05:37
-
-
Save gangchen/4282933 to your computer and use it in GitHub Desktop.
Simple samples for R lesson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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