今天是第五天,学习R语言的数据结构啦
向量
#向量赋值
x <- c(1,2,3)
x <- 1:10
x <- seq(1,10,by = 0.5)
x <- rep(1:3,times = 2)
#从向量中提取元素
##根据位置
x[4]
x[-4]
x[2:4]
x[-(2,:4)]
x[c(1,5)]
#根据值
x[x==10]
x[x<0]
x[x %in% c(1,2,5)]
#数据框
##读取数据
read.table(file = "*.txt",sep = "\t",header = T)
a<-read.table(file = "*.txt",sep = "\t",header = T)
##设置行名和列名
x<-read.csv('*.txt')
colnames(x)
rownames(x)
colnames(x)[1] <- "bio"
xx<-read.csv('*.txt',sep = " ",header = T,row.names =1)
##导出
write.table(x,file = "*.txt",sep = ",",quote = F)
#保存变量与重新加载
save.image(file="*.RDATA")
SAVE(x,file = "*.txt")
load("*.RDATA")
object x not found是指x没有找到,说明在建立x这个变量或文件时出了问题