zoukankan      html  css  js  c++  java
  • R 时间特征提取

    时间特征提取

    library(magrittr)
    library(timetk)
    library(tidyverse)
    
    df <- read_csv("data/nCoV_100k_train.labled.csv") %>% 
        select(`微博id`,`微博发布时间`)
    
    train_df<-df %>%
        mutate(
            mutated_time = str_replace_all(`微博发布时间`, "月", "-") %>%
                str_remove("日") %>%
                paste0("2020-", ., ":00") %>%
                lubridate::as_datetime()
        )
    
    train_data <- 
        train_df %>% 
        # mutate(year = year(t)
        #        ,month = month(t)
        #        ,week = week(t)
        #        ,hour = hour(t)
        #        ,minute = minute(t)
        #        )
        group_by("微博id") %>% 
        arrange(mutated_time) %>% 
        tk_augment_timeseries_signature() %>% 
        mutate_if(is.ordered,as.integer)
    
    train_df %>% head(10)
    微博id
    <dbl>
    微博发布时间
    <chr>
    mutated_time
    
    <S3: POSIXct>
    4.456072e+15	01月01日 23:50	2020-01-01 23:50:00		
    4.456074e+15	01月01日 23:58	2020-01-01 23:58:00		
    4.456054e+15	01月01日 22:39	2020-01-01 22:39:00		
    4.456062e+15	01月01日 23:08	2020-01-01 23:08:00		
    4.455979e+15	01月01日 17:42	2020-01-01 17:42:00		
    4.455961e+15	01月01日 16:28	2020-01-01 16:28:00		
    4.456044e+15	01月01日 21:59	2020-01-01 21:59:00		
    4.456073e+15	01月01日 23:53	2020-01-01 23:53:00		
    4.456060e+15	01月01日 23:00	2020-01-01 23:00:00		
    4.456064e+15	01月01日 23:19	2020-01-01 23:19:00	
    

    sub_replcae_all()

    sub_remove()

    paste0

    glue

  • 相关阅读:
    正则表达式获取远程网页
    Devexpress 常见问题
    CSS 带显示隐藏左部页面按钮
    CSS 技巧积累
    SQL 常用操作
    重置 自增字段 起始值 和 步长
    Devexpress TreeList
    Devexpress GridControl
    JS常用
    ajax跨域请求
  • 原文地址:https://www.cnblogs.com/gaowenxingxing/p/12522439.html
Copyright © 2011-2022 走看看