2017-11-30 5 views
-1

dplyr::mutate_if()が機能しないのはなぜですか?mutate_if()を使用してS3:POSIXct変数を文字(chr)変数に変換するR

  1. here flights <- nycflights13::flights make_datetime_100 <- function(year, month, day, time) { make_datetime(year, month, day, time %/% 100, time %% 100) } flights_df <- flights %>% sample_n(100) %>% filter(!is.na(dep_time), !is.na(arr_time)) %>% mutate( dep_time = make_datetime_100(year, month, day, dep_time), arr_time = make_datetime_100(year, month, day, arr_time), sched_dep_time = make_datetime_100(year, month, day, sched_dep_time), sched_arr_time = make_datetime_100(year, month, day, sched_arr_time)) %>% dplyr::select(origin, dest, ends_with("delay"), ends_with("time"))`

行われるようhere

flights_df %>% as_tibble() %>% mutate_if(is.Date, as.character)

答えて

0

見られるように、今、あなたはPOSIXctを扱っている/文字に日付を変換するためにmutate_if()を使用S3: POSIXct形式で日付とflights_dfを作成します。 xtオブジェクト。あなたは、@Marcoブルーメありがとうis.POSIXct

flights_df %>% as_tibble() %>% mutate_if(is.POSIXct, as.character)

+0

ああを使用する場合

class(flights_df$arr_time[1]) [1] "POSIXct" "POSIXt"

あなたの変換が動作します –

関連する問題