![](/img/trans.png)
[英]What's the difference between integer class and numeric class in R
[英]What's the difference between a double and a numeric?
我想使用數字表示存儲季度數據,其中左側代表年份,右側代表季度。
這是我的代碼
library(tidyverse)
library(fpp)
ausbeer %>%
as_tibble %>%
select(megalitres = x) %>%
mutate(year = as.double(seq(1956, 2009, 0.25)[1:211]))
出於某種原因,它只會將年份顯示為整數,而不會顯示小數。
我已經檢查過,下面是正確的數據,但我很難讓它顯示出來。
我不想將它們編碼為字符,因為這會使可視化更加困難
我想這與你的轉換做data.frame
成tibble
。 在mtcars
數據集上復制您的代碼,我們得到:
mtcars %>%
as_tibble() %>%
mutate(year = as.double(seq(1956, 2009, 0.25)[1:nrow(mtcars)])) %>%
dplyr::select(year) %>%
head
# year
# <dbl>
# 1 1956
# 2 1956.
# 3 1956.
# 4 1957.
# 5 1957
# 6 1957.
如果我們評論as_tibble
則有以下不同:
# year
# 1 1956.00
# 2 1956.25
# 3 1956.50
# 4 1956.75
# 5 1957.00
# 6 1957.25
用as.numeric
交換as.double
不會改變任何東西。 從?double
:
as.double is a generic function. It is identical to as.numeric.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.