Re: [問題] 資料篩選(日期問題)
※ 引述《tony1331 (BLUE)》之銘言:
: [問題類型]:
: (我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
: [軟體熟悉度]:
: (沒寫過程式,R 是我的第一次)
: [問題敘述]:
: http://i.imgur.com/woqwvM1.jpg
: Table有一欄是時間,假設是7-8月的資料,
: 請問如果我只想要1點到2點的資料該如何寫
: (不管日期 只要1點到2點)
: 謝謝~
: -----
: Sent from JPTT on my Asus ASUS_Z012DA.
timedata <- as.POSIXct(c("2017-01-01 01:30:20", "2017-05-02 01:12:20",
"2017-07-21 05:30:20", "2017-04-27 01:13:40", "2016-12-27 13:13:40"),
"%Y-%m-%d %H:%M:%S", tz="GMT")
id <- c(1:5)
df <- data.frame(id, timedata)
===================以上是隨意做一個data.frame來示範=====================
因為是1點到2點 所以是01:00:00~01:59:59
以下提供直接寫迴圈的方式:
time_strsplit<- c()
for(i in 1:nrow(df)){
time_strsplit <- c(time_strsplit,
as.numeric(substr(strsplit(as.character(df$timedata), " ")[[i]][2], 1, 2)))
}
df_subset <- subset(cbind(df, time_strsplit), time_strsplit == 1)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.34.124.238
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1506010831.A.E5F.html
→
09/22 19:34, , 1F
09/22 19:34, 1F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):