gpt4 book ai didi

R 使用 NA 数据类型 dbl 创建 tibble 行

转载 作者:行者123 更新时间:2023-12-01 23:54:09 26 4
gpt4 key购买 nike

如何以 tibble 格式创建一行,数据类型为 <dbl>

(不是 <lgl>,如下例所示)

NAs <- rep(NA, 10)
NAs1 <- t(tibble(NAs))
NAs2 <- as_tibble(NAs1)
NAs2

# # A tibble: 1 x 10
# V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
# <lgl> <lgl> <lgl> <lgl> <lgl> <lgl> <lgl> <lgl> <lgl> <lgl>
# 1 NA NA NA NA NA NA NA NA NA NA

提前致谢。

最佳答案

您可以使用NA_real_来指定NA的类型。

tibble::as_tibble(t(rep(NA_real_, 10)))

# # A tibble: 1 x 10
# V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
# 1 NA NA NA NA NA NA NA NA NA NA

来自?NA:

NA is a logical constant of length 1 which contains a missing value indicator. NA can be coerced to any other vector type except raw. There are also constants NA_integer_, NA_real_, NA_complex_ and NA_character_ of the other atomic vector types which support missing values: all of these are reserved words in the R language.

关于R 使用 NA 数据类型 dbl 创建 tibble 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63052472/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com