【问题标题】:Trying to count number of times a year is in a timestamp in R试图计算一年的次数在 R 的时间戳中
【发布时间】:2014-03-25 16:53:11
【问题描述】:

我已经发布了我们正在使用的代码,运行速度非常快。我应该弄清楚这个问题。

数据集中有多少事件发生在 2011 年?

所有时间戳都没有那个日期,但 lastModified 列有。我正在尝试使用此代码在 2011 年返回 1,如果不是,则返回 0,但它们都返回 0。请帮忙!

theData$year2011 <- ifelse(theData$lastModified == "2011*", 1,0)

那是行不通的代码。这是设置数据的代码

require(rjson)
require(plyr)

dataPath <- "http://getglue-data.s3.amazonaws.com/getglue_sample.tar.gz"

theCon<-gzcon(url(dataPath))

n.rows <- 1000
theLines <-readLines(theCon, n=n.rows)

str(theLines)
theLines[1]
theRead<-lapply(theLines[-1],fromJSON)

theData<-ldply(theRead,as.data.frame)

View(theData)

【问题讨论】:

    标签: r count timestamp


    【解决方案1】:
    theData$year2011 <- ifelse(grepl('^2011.*', theData$lastModified), 1,0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-04
      • 2022-11-17
      • 1970-01-01
      • 1970-01-01
      • 2017-12-07
      相关资源
      最近更新 更多