TM - 用特殊的日子聚类数据变量
问题描述:
从香港专业教育学院拿到注册下列数据:TM - 用特殊的日子聚类数据变量
'data.frame': 682 obs. of 6 variables:
$ X : int 1 2 3 4 5 6 7 8 9 10 ...
$ id : Factor w/ 674 levels "id","rn106322397",..: 672 671 670 669 668 667 666 665 664 663 ...
$ quote : Factor w/ 606 levels "\"Picturesque Lake Konigssee\"",..: 389 139 113 149 384 39 176 598 199 603 ...
$ rating : Factor w/ 6 levels "1","2","3","4",..: 3 5 5 5 4 5 5 5 4 5 ...
$ date : Factor w/ 505 levels "date","Reviewed 1 August 2014\n",..: 200 200 427 427 427 443 434 351 313 494 ...
$ reviewnospace: Factor w/ 674 levels "- Good car parking facilities- Organized boat trips- Ensure that you have enough time at hand for the boat trip",..: 624 573 144 211 507 26 351 672 451 249 ...
我尝试集群日期的基础上的数据,让两组 - 冬季和夏季度假。有了这个集群,我想在之后分析评论。我现在用的是TM封装,并用下面的代码试了一下:
> x <- read.csv ("seeganz.csv", header = TRUE, stringsAsFactors = FALSE, sep = ",")
> corp <- VCorpus(VectorSource(x$reviewnospace), readerControl = list(language = "eng"))
> meta(corp,tag = "date") <- x$date
> idx <- meta(corp, "date") == 'December'
但它是不工作的内容说0文件:
> corp [idx]
<<VCorpus>>
Metadata: corpus specific: 0, document level (indexed): 1
Content: documents: 0
随着日期的结构为“点评1 2014年8月“,我该如何修改此代码才能获得,例如11月至2月的评论?
你有什么想法我可以解决这个问题吗?
谢谢。
答
通用方法:
- 使用
substr(date, 10, nchar(date))
去1 August 2014
把这种新的载体dateNew -
正常使用日期函数例如as.Date(dateNew,...)来改变dateNew成Date类型的载体,你可以做的子集/减法等操作 引用从http://www.statmethods.net/input/dates.html
# use as.Date() to convert strings to dates mydates <- as.Date(c("2007-06-22", "2004-02-13")) # number of days between 6/22/07 and 2/13/04 days <- mydates[1] - mydates[2]
谢谢您的回复!我用下面的代码'> dateNew dateNew [1]“2015年10月27日”“2015年10月25日”“”2015年10月23日“”2015年10月23日“ [5 ]“2015年10月21日”“2015年10月21日”“2015年10月21日”“2015年10月18日” [9]“2015年10月18日”“2015年10月17日” > as.Date(dateNew,“%d%B%Y “) [1]不适用不适用不适用不适用不适用不适用不适用不过NA为什么要拿到NA? –
@LauraHiemer:更新的答案请审查。谢谢。另外,我认为你需要尝试nchar(日期)而不是24。原因是nchar(“2015年10月25日”)= 24和nchar(“2015年8月25日”)= 23。 – user2007598