R言語tibbleによる単純なデータ・ボックスの実装

599 ワード

library(tidyverse)

####  tibble
as_tibble(iris)      #       tibble

tibble(
  x = 1:5,
  y = 1,
  z = x ^ 2 + y
)                    #  tibble()        tibble

tribble(
  ~x, ~y, ~z, 
  #--|--|---- 
  "a", 2, 3.6, 
  "b", 1, 8.5
)


####  
tibble(
  a = lubridate::now() + runif(1e3) * 86400, b = lubridate::today() + runif(1e3) * 30, c = 1:1e3,
  d = runif(1e3),
  e = sample(letters, 1e3, replace = TRUE)
)

nycflights13::flights %>%
  print(n = 10, width = Inf)    #  10    

####        
#           tibble,   as.data.frame() tibble      
(tb