Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中'str'报告的第二栏是什么?这一栏中的'atomic'是什么意思?_R - Fatal编程技术网

R中'str'报告的第二栏是什么?这一栏中的'atomic'是什么意思?

R中'str'报告的第二栏是什么?这一栏中的'atomic'是什么意思?,r,R,在我的数据框上使用str(survey_OM)表示我所有的数字数据都是原子的。如果我使用类(survey\u OM$perc.OM)它将返回numeric 我一直认为str的第二列显示了数据的类别,但它似乎没有那么简单。。。因此,我的问题是: str报告的第二列是什么 什么是原子的,它与数值的有何不同 在这种情况下,为什么数据显示为atomic,而不是num或int 谢谢。 dput(头(调查对象,20))提供: > dput(head(survey_OM, 20)) structur

在我的数据框上使用
str(survey_OM)
表示我所有的数字数据都是
原子的
。如果我使用
类(survey\u OM$perc.OM)
它将返回
numeric

我一直认为
str
的第二列显示了数据的类别,但它似乎没有那么简单。。。因此,我的问题是:

  • str
    报告的第二列是什么
  • 什么是原子的,它与数值的有何不同
  • 在这种情况下,为什么数据显示为
    atomic
    ,而不是
    num
    int
  • 谢谢。
    dput(头(调查对象,20))
    提供:

    > 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)
    的完整输出为:

    > 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"
    

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

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

    因此,
    数值
    原子
    的模式之一


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

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

    查看
    utils:::str.default
    ,如果以下
    if
    语句为真,我们会得到
    int
    num
    等的常规输出:

    if (     is.vector(object) 
         || (is.array(object) && is.atomic(object))
         ||  is.vector(object, mode = "language") 
         || is.vector(object, mode = "symbol")
       )
    
    如果该语句为false(否则它将是
    int
    num
    ,等等),我们将得到
    atomic

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

    d <- data.frame(a=1:4, b=5:8)
    attr(d$b, "tmp") <- "surprise!"
    

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

    @KennyPeanuts:关于(2),我认为“原子”是以下数据类型的通用术语-字符、复数、双精度、整数,和逻辑。@KennyPeanuts:关于(1),如果我正确理解您的问题,您不知道为什么“my.data”的“notes”列显示为“Factor”。R通常强制数据和自然数(1,2,3,…)对应,以减少内存使用。这些与原始数据相对应的数字称为“因子”。例如,如果我有一个向量('a','b','c','a','a','b'),R认为没有理由存储六个字符串,而是创建一个对应关系'a':1',b':2',c':3,并将向量存储为(1,2,3,1,1,2)。@Jubbles,感谢您的输入。这并不是我所困惑的。我理解票据的
    系数
    。我不清楚的是,为什么数字变量(例如perc.OM)被指定为
    atomic
    ,而不是
    num
    。我仍然不完全清楚什么是
    原子的
    ,但正如您所建议的,它是一种包含数字的通用数据类型。如果我使用typeof(my.data$perc.OM),我会得到
    double
    (我不确定这与类numeric有何不同)。我想我需要更好地理解R数据类型和类。你能包括整个
    str()
    输出吗?至少你已经把顶部剪掉了。此外,部分或全部数据将是有用的。如果这是一个数据帧,
    dput(head(my.data,20))
    应该足够我们使用。请编辑您的Q以包含此信息。@Gavin Simpson,很抱歉我花了这么长时间才回复-我已经添加了您建议的对问题有帮助的数据。谢谢您的帮助。但是请尝试使用
    str()
    来输出
    原子的
    ,而不是数据的特定模式。。。我认为这是Q的主旨,正如上面OP的评论所暗示的那样。为什么它显示的是原子模式而不是实际模式?是的,但并没有真正回答问题的主旨-为什么原子模式而不是实际模式?一个人是如何达到这样一个目标的?谢谢你对我的问题的意见。这确实帮助我更好地理解引擎盖下发生的事情。。。我已经添加了所请求的
    dput
    数据,希望这将使问题更清楚。感谢您的回答。我删除了注释(即额外属性),并且
    str
    中的
    模式回到了预期结果。我刚开始添加注释,但我想我需要一个新的方法来找到一种不同的方法来注释我的数据帧。再次感谢+1破解
    str
    代码。我看到了同样的陈述,但没有像你那样做出正确的解释。
    > 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!"