首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“R中的is ` report”的第二栏是什么,这一栏中的“原子”是什么意思?

“R中的is ` report”的第二栏是什么,这一栏中的“原子”是什么意思?
EN

Stack Overflow用户
提问于 2011-04-27 18:50:43
回答 3查看 1.8K关注 0票数 7

在我的数据框架上使用str(survey_OM)表示我所有的数值数据都是atomic。如果我使用class(survey_OM$perc.OM),它将返回numeric

我一直认为str的第二列显示了数据的类,但看起来并不那么简单.所以我的问题是:

reporting?

  • What的第二列是atomic,在这种情况下,它与numeric

  • Why有什么不同,数据会以atomic而不是numint

的形式出现

谢谢。

dput(head(survey_OM, 20))提供:

代码语言:javascript
复制
> dput(head(survey_OM, 20))
  structure(list(lake = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 
  3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("E-2", 
  "E-4", "E pond", "EX 1", "GTH 110", "GTH 112", "GTH 114", "GTH 156", 
  "GTH 91", "GTH 98", "N-1", "NE-10", "NE-11", "NE-3", "NE-8", 
  "NE-9", "NE-9b", "S-10", "S-11", "S-3", "S-6", "S-7"), class = "factor"), 
  date = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("2007/06/15", 
  "2007/06/18", "2007/06/19", "2007/06/20", "2007/06/21", "2007/06/27", 
  "2007/06/29", "2007/07/07", "2007/07/19", "2007/07/20", "2008/07/26", 
  "2008/07/30", "2008/08/04", "2008/08/06"), class = "factor"), 
  depth = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("E", 
  "epi", "H", "hypo"), class = "factor"), 
  depth.m = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = c("", "10.9", "12.9", "1.5", "2", 
  "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "3", "3.1", 
  "3.5", "4", "4.2", "4.8", "4.9", "5", "5.1", "5.5", "6", 
  "6.5", "7", "7.2", "9.9", "not recorded"), class = "factor"), 
  rep = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("A", 
  "B", "C"), class = "factor"), 
  sed = c(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L), 
  notes = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("", 
  "col on SE side", "lg snail shell", "not collected", "very hard sediments"
  ), class = "factor"), 
  dry.mass = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 
  perc.OM = c(47.1300248455119, 47.4260808104607, 47.7349307375515, 46.4501104675465, 44.1513415737111, 43.5608499678045, 42.9921259842519, 42.2674677347574, 39.6643311064039, 
  39.0968130690949, 46.7768514928267, 46.9211608642763, 46.7877013177158, 
  47.0709930313588, 44.3241152581706, 43.7905468025952, 41.706074101281, 
  36.5061097383474, 37.4329041152142, 37.7757939038389)), .Names = c("lake", 
  "date", "depth", "depth.m", "rep", "sed", "notes", "dry.mass", 
  "perc.OM"), comment = c("working data frame of the sediment char from the 2007 sed    survey       created:", "Wed Apr 27 14:23:33 2011"), row.names = c(NA, 20L), class = "data.frame")

str(survey_OM)的全部输出是:

代码语言:javascript
复制
> str(survey_OM)
'data.frame':   780 obs. of  9 variables:
 $ lake    : Factor w/ 22 levels "E-2","E-4","E pond",..: 3 3 3 3 3 3 3 3 3 3 ...
  ..- attr(*, "comment")= chr "names of the lakes"
 $ date    : Factor w/ 14 levels "2007/06/15","2007/06/18",..: 2 2 2 2 2 2 2 2 2 2 ...
  ..- attr(*, "comment")= chr "date that the cores were collected"
 $ depth   : Factor w/ 4 levels "E","epi","H",..: 2 2 2 2 2 2 2 2 2 2 ...
  ..- attr(*, "comment")= chr "relative depth ID; epi = shallowest corable Z, hypo =   deepest Z, S, M, D = shallow, med, deep"
 $ depth.m : Factor w/ 28 levels "","10.9","12.9",..: 6 6 6 6 6 6 6 6 6 6 ...
  ..- attr(*, "comment")= chr "depth that core was collected in m"
 $ rep     : Factor w/ 3 levels "A","B","C": 1 1 1 1 1 1 1 1 1 1 ...
  ..- attr(*, "comment")= chr "replicate ID for core"
 $ sed     : atomic  0 1 2 3 4 5 6 7 8 9 ...
  ..- attr(*, "comment")= chr "depth of sample from sed/water interface in cm"
 $ notes   : Factor w/ 5 levels "","col on SE side",..: 1 1 1 1 1 1 1 1 1 1 ...
  ..- attr(*, "comment")= chr "comments on sample"
 $ dry.mass: atomic  0 0 0 0 0 0 0 0 0 0 ...
  ..- attr(*, "comment")= chr "dry mass of the sediment at that sed Z in g/m^2"
 $ perc.OM : atomic  47.1 47.4 47.7 46.5 44.2 ...
  ..- attr(*, "comment")= chr "percent OM of the samp. based on LOI at 550d C"
 - attr(*, "comment")= chr  "working data frame of the sediment char from the 2007 sed survey created:" "Wed Apr 27 14:23:33 2011"
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-04-28 01:28:52

查看utils:::str.default,我们可以看到,如果以下if语句为真,则得到intnum等的通常输出:

代码语言:javascript
复制
if (     is.vector(object) 
     || (is.array(object) && is.atomic(object))
     ||  is.vector(object, mode = "language") 
     || is.vector(object, mode = "symbol")
   )

如果这个语句是假的,我们就得到atomic (否则它会是intnum等)。

查看is.vector的帮助页面,我们发现只有当它是一个向量时,它才返回true,除了名称之外没有其他属性。下面是一个数据框架,其中b有一个额外的属性:

代码语言:javascript
复制
d <- data.frame(a=1:4, b=5:8)
attr(d$b, "tmp") <- "surprise!"

在它上调用str给出了atomic for b而不是int

代码语言:javascript
复制
> str(d)
'data.frame':   4 obs. of  2 variables:
 $ a: int  1 2 3 4
 $ b: atomic  5 6 7 8
  ..- attr(*, "tmp")= chr "surprise!"

我在您的编辑中看到,您在数据框架的元素上有额外的属性,并且您也得到了关于属性的这些额外行,所以这似乎解释了这一点。

票数 8
EN

Stack Overflow用户

发布于 2011-04-27 21:01:39

R将数据类型划分为原子类型和递归类型。大多数人称之为向量的东西都是原子的(就像目前有几个人提到的那样)。列表可以具有任意程度的复杂性,即列表中的列表,并将从is.atomic()返回FALSE。原子向量可以有属性,而不失去它们的“原子性”。

票数 2
EN

Stack Overflow用户

发布于 2011-04-27 20:55:25

我相信你的三个问题基本上归结为一件事。

str()的第二列返回对象的mode,而不是类。指令?atomic重定向到?vector,其中声明:“原子模式是”逻辑“、”整数“、”数字“(同义词”双“)、”复杂“、”字符“和”原始“。

因此,numericatomic的一种模式。

mode是指对象的存储模式。有关更多详细信息,请参阅?mode

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5809017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档