数据结构
向量赋值方法
x <- c(22,32,12,45,45)
x
[1] 22 32 12 45 45
b <- 1:12
c <- seq(1,4,by=1)
c
[1] 1 2 3 4
c <- seq(1,4,by=2)
c
[1] 1 3
d <- rep(1:3,times=2)
d
[1] 1 2 3 1 2 3```
提取元素
x[-3]
[1] 22 32 45 45
x[1:3]
[1] 22 32 12
x[c(1,3)]
[1] 22 12
x[x<25]
[1] 22 12
x[x %in% c(22,45,65,34)]
[1] 22 45 45
数据框
getwd()
[1] "C:/Users/luobo/Documents" #显示工作目录——去工作目录新建doudou文本
读取数据
read.table(file = "doudou.txt",sep = "",header = T)
X1.X2
1 A,1
2 B,
3 C,
4 D,3
5 E,
x <-read.csv('doudou.txt')
x
X1 X2
1 A 1
2 B NA
3 C NA
4 D 3
5 E NA
a
X1.X2
1 A,1
2 B,
3 C,
4 D,3
5 E,
设置行名和列名
colnames(x)
[1] "X1" "X2"
row.names(x)
[1] "1" "2" "3" "4" "5"
rownames(x)
[1] "1" "2" "3" "4" "5"
导出数据框
write.table(x,file = "yu.txt",sep = ",",quote = F)
保存和加载变量
save.image(file = "bioinfoplanet.RData")
load("bioinfoplanet.RData")
提取元素
x[1,2]
[1] 1
x[-3]
X1 X2
1 A 1
2 B NA
3 C NA
4 D 3
5 E NA