简体   繁体   English

如何在r中创建tibble?

[英]How to create tibble in r?

How to create tibble in r, which have name as indicated in the figure.如何在 r 中创建 tibble,其名称如图所示。 I want the object access structure like this:我想要这样的对象访问结构:

S10m$ALAEF$validdate
S10m -object
ALAEF - dataframe/table name
validdate is column name in dataframe

enter image description here在此处输入图片说明

I see that I was not clear.我看我没说清楚。 I want something like this:我想要这样的东西:

    > str(u10)
List of 1
 $ ALAEF: tibble [4,624 x 12] (S3: tbl_df/tbl/data.frame)
  ..$ SID         : int [1:4624] 11060 11080 11800 11803 11805 11806 11810 11812 11813 11815 ...
  ..$ fcdate      : int [1:4624] 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 ...
  ..$ fcst_cycle  : chr [1:4624] "00" "00" "00" "00" ...
  ..$ leadtime    : int [1:4624] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ parameter   : chr [1:4624] "u10m" "u10m" "u10m" "u10m" ...
  ..$ units       : chr [1:4624] "m/s" "m/s" "m/s" "m/s" ...
  ..$ validdate   : int [1:4624] 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 ...
  ..$ z           : int [1:4624] 10 10 10 10 10 10 10 10 10 10 ...
  ..$ ALAEF_mbr000: num [1:4624] 0.651 0.635 -0.451 -0.662 -1.357 ...
  ..$ ALAEF_mbr001: num [1:4624] 0.654 0.842 -0.471 -0.502 -1.346 ...
  ..$ ALAEF_mbr002: num [1:4624] 0.736 0.619 -0.108 -0.53 -1.631 ...
  ..$ ALAEF_mbr003: num [1:4624] 0.815 0.8 -0.286 -0.271 -1.615 ...

but my created data looks like this:但我创建的数据如下所示:

> str(wind)
tibble [4,624 x 17] (S3: tbl_df/tbl/data.frame)
 $ SID           : int [1:4624] 11060 11080 11800 11803 11805 11806 11810 11812 11813 11815 ...
 $ fcdate        : int [1:4624] 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 ...
 $ fcst_cycle    : chr [1:4624] "00" "00" "00" "00" ...
 $ leadtime      : int [1:4624] 0 0 0 0 0 0 0 0 0 0 ...
 $ parameter.x   : chr [1:4624] "u10m" "u10m" "u10m" "u10m" ...
 $ units         : chr [1:4624] "m/s" "m/s" "m/s" "m/s" ...
 $ validdate     : int [1:4624] 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 1597968000 ...
 $ z             : int [1:4624] 10 10 10 10 10 10 10 10 10 10 ...
 $ ALAEF_mbr000.x: num [1:4624] 0.651 0.635 -0.451 -0.662 -1.357 ...
 $ ALAEF_mbr001.x: num [1:4624] 0.654 0.842 -0.471 -0.502 -1.346 ...

How we can see, object wind not have $ALAEF: tibble [............] part我们怎么看,对象没有 $ALAEF: tibble [……] 部分

Attributes for u10: u10 的属性:

> attributes(u10)
$names
[1] "ALAEF"

Attributes for wind:风属性:

> attributes(wind)
$names
 [1] "SID"            "fcdate"         "fcst_cycle"     "leadtime"
 [5] "parameter.x"    "units"          "validdate"      "z"
 [9] "ALAEF_mbr000.x" "ALAEF_mbr001.x" "ALAEF_mbr002.x" "ALAEF_mbr003.x"
[13] "parameter.y"    "ALAEF_mbr000.y" "ALAEF_mbr001.y" "ALAEF_mbr002.y"
[17] "ALAEF_mbr003.y"

$row.names
   [1]    1    2    3    4    5    6    7    8    9   10   11   12   13   14
  [15]   15   16   17   18   19   20   21   22   23   24   25   26   27   28
  [29]   29   30   31   32   33   34   35   36   37   38   39   40   41   42
  [43]   43   44   45   46   47   48   49   50   51   52   53   54   55   56

Can you give me some example how to do it in r ?你能给我一些例子如何在 r 中做到这一点吗?

You could nest a dataframe (or tibble) inside a tibble:您可以在 tibble 中嵌套数据框(或 tibble):

library(tibble)

S10m <- tibble(
  ALAEF = data.frame(
    validdate = as.Date(numeric(0))
  )
)

An alternative to a tibble would be a named list. tibble 的替代方法是命名列表。 Your choice of data structure depends on your particular use-case.您对数据结构的选择取决于您的特定用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM