R中的数据和data.frame有什么区别?

时间:2018-04-28 12:56:05

标签: r

我知道data.frame是一个二维矩阵,其中包含不同类型的列。我认为dataR中的另一种数据结构,可能需要多个data.frame

RStudio,现在我有两个datadcdpdb

Set width of a "Position: fixed" div relative to parent div

我试图了解它们的属性:

> dcd

   Total Frames#: 101
   Total XYZs#:   19851,  (Atoms#:  6617)

    [1]  65.59  84.65  90.92  <...>  59.76  55.48  83.68  [2004951] 

+ attr: Matrix DIM = 101 x 19851

> class(dcd)
[1] "xyz"    "matrix"

> dcd$xyz
Error in dcd$xyz : $ operator is invalid for atomic vectors

> pdb

 Call:  read.pdb(file = pdbfile)

   Total Models#: 1
     Total Atoms#: 6598,  XYZs#: 19794  Chains#: 2  (values: L H)

     Protein Atoms#: 6598  (residues/Calpha atoms#: 442)
     Nucleic acid Atoms#: 0  (residues/phosphate atoms#: 0)

     Non-protein/nucleic Atoms#: 0  (residues: 0)
     Non-protein/nucleic resid values: [ none ]

   Protein sequence:
      DIQMTQSPSSLSASVGDRVTITCKASQNVRTVVAWYQQKPGKAPKTLIYLASNRHTGVPS
      RFSGSGSGTDFTLTISSLQPEDFATYFCLQHWSYPLTFGQGTKVEIKRTVAAPSVFIFPP
      SDEQLKSGTASVVCLLNNFYPREAKVQWKVDNALQSGNSQESVTEQDSKDSTYSLSSTLT
      LSKADYEKHKVYACEVTHQGLSSPVTKSFNRGECEVQLVESGGGL...<cut>...TSAA

+ attr: atom, xyz, calpha, call

> class(pdb)
[1] "pdb" "sse"

> pdb$xyz

   Total Frames#: 1
   Total XYZs#:   19794,  (Atoms#:  6598)

    [1]  24.33  14.711  -3.854  <...>  -34.374  -6.315  14.986  [19794] 

+ attr: Matrix DIM = 1 x 19794

我的问题是:

  1. dcd是否与101行和19851列的矩阵类似?
  2. class(dcd)输出"xyz""matrix",这是否意味着dcd同时属于"xyz""matrix"类型?
  3. 如何创建包含多个data的{​​{1}} pdb
  4. e.g。如果我有

    data.frame

    如何将students <- data.frame(c("Cedric","Fred","George"),c(3,2,2)) names(students) <- c("name", "year") teachers <- data.frame(c("John","Alice","Mike"),c(6,9,5)) names(teachers) <- c("name", "year") students合并到名为teachers的{​​{1}}中,以便我可以使用datapeople?< / p>

1 个答案:

答案 0 :(得分:1)

如果您要询问如何创建名为dataframe的{​​{1}},那么您可以使用peoplepeople$students访问相关人员的姓名,实现这一目标的代码是:

people$teachers

people <- data.frame(students = students$name, teachers = teachers$name) people$students 将是一个如下所示的数据框: enter image description here

如果您想要people,可以创建如下列表对象:

list

people2 <- as.list(c("students" = students, "teachers" = teachers)) people2$students.name # returns [1] Cedric Fred George 将是一个列表: enter image description here

查看列表中每个项目旁边的people2(美元符号)?这告诉你如何访问它们。如果您需要$,那么teachers.name会为您执行此操作。

至于你的其他问题:

  1. dcd是否类似于101行和19851列的矩阵?
  2. 您可以使用print(people2$teachers.name)dim()ncol()来验证类矩阵对象的尺寸。在你的情况下,它有101行和19851列。

    1. nrow()输出&#34; xyz&#34;和&#34;矩阵&#34;,是否意味着dcd属于&#34; xyz&#34;和&#34;矩阵&#34;类型在同一时间?
    2. 简单地说,您可以认为它继承了class(dcd)类以及matrix。您可能需要阅读classes and inheritance in R

      1. 如何创建pdb等数据,其中包含多个data.frame?
      2. 看看上面的代码。 xyz创建了people2 <- as.list(c("students" = students, "teachers" = teachers))&#34;多个&#34; dataframes。