我是基本的 R 用戶。但是我無法創建顯示weather資料集的每日最低溫度(以 F 為單位)的圖,該圖在nycflights13. 我需要創建一個名為datewith的新列str_c,date應如下給出“YYYY-MM-DD”。我使用 lubridate 包,但它給出了錯誤。
有人對此有解釋嗎?
uj5u.com熱心網友回復:
lubridate::make_date可以解決問題。
下面是檔案。
make_date(year = 1970L, month = 1L, day = 1L)
library(tidyverse)
library(nycflights13)
library(lubridate)
df <- weather
df <- df %>%
mutate(date = make_date(year, month, day)) %>%
group_by(date) %>%
summarize(min_temp = min(temp)*1.8 32)
> df
# A tibble: 364 x 2
date min_temp
<date> <dbl>
1 2013-01-01 80.5
2 2013-01-02 73.4
3 2013-01-03 78.9
4 2013-01-04 84.1
5 2013-01-05 89.6
6 2013-01-06 91.5
7 2013-01-07 89.6
8 2013-01-08 84.1
9 2013-01-09 93.2
10 2013-01-10 102.
# ... with 354 more rows
ggplot(df) geom_point(aes(x = date, y = min_temp))

這也可能解決您的代碼。
as.Date(str_c(weather$year, "-", weather$month, "-", weather$day), format = "%Y-%m-%d")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/436095.html
上一篇:如何在ggplot2`scale_...`函式中添加函式?
下一篇:如何在C#中顯示空陣列?
