Day 5 - 數(shù)據(jù)結(jié)構(gòu)
Vector

圖片來源:生物星球
eg.
x <- c(1,2,3)
x <- seq(1,10, by = 0.5) # 1-10 之間每隔0.5取一個(gè)數(shù)
x <- rep(1:3, times = 2) # 1-3 重復(fù)2次
- 從向量中提取元素
- 根據(jù)元素位置
- x[4] # x第4個(gè)元素
- x[-4] # 除了第4個(gè)元素之外剩余的元素
- x[2:4] # 第2到4個(gè)元素
- x[-(2:4)] # 除了第2-4個(gè)元素
- x[c(1,5)] # 第1個(gè)和第5個(gè)元素
- 根據(jù)值
- x[x==10] #等于10的元素
- x[x<0]
- x[x %in% c(1,2,5)] #存在于向量c(1,2,5)中的元素
Data frame
read.table(file = "huahua.txt", sep = "\t", header =T)
header: a logical value indicating whether the file contains the names of the variables as its first line. If missing, the value is determined from the file format: header is set to TRUE if and only if the first row contains one fewer field than the number of columns.
sep: the field separator character. Values on each line of the file are separated by this character. If sep = "" (the default for read.table) the separator is ‘white space’, that is one or more spaces, tabs, newlines or carriage returns.
設(shè)置行列名
colnumes, rownames數(shù)據(jù)框的導(dǎo)出
write.table(x,file ="yu.txt", sep =",", qupte =F)變量的保存與重新加載
格式:RData
save.image(file = "bioinfoplanet.RData")
保存當(dāng)前所有變量
save(x, file = "test.RData")
保存其中一個(gè)變量
load(test.RData")
再次使用RData時(shí)的加載命令
- 提取元素
x[x,y]
第x行第y列
x[x,]
第x行
x[,y], or x[y]
第y列
x[a:b]
第a列到第b列
x[c(a,b)]
第a列和第b列
x$列名
提取某列
如果oject X not found, 應(yīng)該是變量X 沒有賦值
