学习小组Day5笔记-May

Day 5 - 数据结构

Vector

1622499978861.jpg

图片来源:生物星球

eg.
x <- c(1,2,3)
x <- seq(1,10, by = 0.5) # 1-10 之间每隔0.5取一个数
x <- rep(1:3, times = 2) # 1-3 重复2次

  1. 从向量中提取元素
  • 根据元素位置
    • x[4] # x第4个元素
    • x[-4] # 除了第4个元素之外剩余的元素
    • x[2:4] # 第2到4个元素
    • x[-(2:4)] # 除了第2-4个元素
    • x[c(1,5)] # 第1个和第5个元素
  1. 根据值
    • 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.

  1. 设置行列名
    colnumes, rownames

  2. 数据框的导出
    write.table(x,file ="yu.txt", sep =",", qupte =F)

  3. 变量的保存与重新加载
    格式:RData
    save.image(file = "bioinfoplanet.RData")
    保存当前所有变量

save(x, file = "test.RData")
保存其中一个变量

load(test.RData")
再次使用RData时的加载命令

  1. 提取元素
    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, 应该是变量X 没有赋值


1622506730445.jpg
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 数据结构 1.向量 1.1.区分标量和向量 元素,是指数字或者字符串等,根据元素可区分两个词 标量:一个元素组成的...
    kinder_85a2阅读 314评论 0 0
  • R-数据结构 表格在R语言中叫数据框 函数或者命令不会用时,除了百度/谷歌搜索以外,用这个命令查看帮助:?read...
    zZ_f79f阅读 168评论 0 0
  • 数据结构 向量:元素:数字或字符串 标量(一个元素) 向量(多个元素) 从向量提取元素: 元素位置 x[4] #x...
    Nicole晶阅读 176评论 0 0
  • 向量 元素:数字或字符串(字符串使用时必须加引号)标量:一个元素组成的变量向量:多个元素组成的变量赋值:<- 从向...
    听风_7e46阅读 204评论 0 0
  • 表情是什么,我认为表情就是表现出来的情绪。表情可以传达很多信息。高兴了当然就笑了,难过就哭了。两者是相互影响密不可...
    Persistenc_6aea阅读 125,987评论 2 7