-3

我是 R 新手,但尝试分析数据集这是原始链接https://cache-default03g.cdn.yandex.net/download.yandex.ru/company/jobs/test_data_dreams.txt

我的代码是(我使用 R Studio 0.99.903 & R 3.3.1)

# get the data from url url <- "https://cache- default03g.cdn.yandex.net/download.yandex.ru/company/jobs/test_data_dreams.txt" testdata <-read.table(url, header = T, sep="\t") #install packages for text mining to analyze the queries install.packages("slam") install.packages("tm") library(tm) #convert unix to GMT testdata$timestamp..unix. <- as.POSIXct(as.numeric(as.character(testdata$timestamp..unix.)),origin="1970-01-01",tz="GMT") #delete some words testdata$query <- gsub("к чему снится ", "\\1", testdata$query) testdata$query <- gsub("к чему сниться ", "\\1", testdata$query) testdata$query <- gsub(" к чему снится", "\\1", testdata$query) testdata$query <- gsub(" к чему сниться", "\\1", testdata$query) testdata$query <- gsub("снится ", "\\1", testdata$query) testdata$query <- gsub(" к чему", "\\1", testdata$query)'

现在我的数据框看起来是这样的。

> head(testdata) timestamp..unix. query city 1 2016-02-04 10:15:13 волна вынесла на берег Москва 2 2016-02-24 10:28:53 бегать наперегонки Екатеринбург 3 2016-02-07 15:31:51 свадьба мужчине со своей женой Владикавказ 4 2016-02-05 08:06:24 иголка медицинская Тамбов 5 2016-02-16 15:21:16 давняя знакомая Калининград 6 2016-02-27 03:38:46 белый маленький котенок Новосибирск

现在,我正在尝试绘制查询以查看它们在白天(也包括在月内)的总体分布以及我拥有的每个城市。

您能否帮助我使用我应该选择分别读取日期和时间的工具,并且不绘制查询本身,而只是绘制查询的分布。

谢谢!

4

1 回答 1

0

您可以使用lubridate包,很容易从日期中提取日期和时间,然后对它们进行测试。例如 :

 # Add a column for day
df$day <- day(df$timestampcol)

# Add a column for the hour
df$hour <- hour(df$timestampcol)

对于情节,我推荐您使用ggplot2包,在这里您将找到一个绘制时间序列的示例。

于 2016-08-23T16:08:19.763 回答