简体   繁体   English

R - 交通数据

[英]R - Traffic Data

I'm hoping for some help with my data.我希望对我的数据有所帮助。 It is presented as traffic data by year, region_id, road__category_id and all_motor_vehicles.它按年份、region_id、road__category_id 和 all_motor_vehicles 表示为交通数据。 I hope to add all the all_motor_vehicle data for all the road_category_id variables for year region and each year.我希望为年份区域和每年的所有 road_category_id 变量添加所有 all_motor_vehicle 数据。

For example, for Wales in 1993 I would have the sum of all the motor vehicle data for the road category.例如,对于 1993 年的威尔士,我将获得道路类别的所有机动车辆数据的总和。

Any help would be greatly appreciated.任何帮助将不胜感激。

Data:数据:

1

I recommend using dplyr from the tidyverse package to group the data and do calculations.我建议使用dplyr中的tidyverse对数据进行分组并进行计算。 Assuming your data is called dat :假设您的数据称为dat

Get the total number of observations for 1993 from Wales for each road cat:获取威尔士 1993 年对每只公路猫的观察总数:

require(tidyverse)
dat %>%
  filter(year==1993,
         region_id=='Wales') %>%
  group_by(road_catagory_id) %>%
  summarize(observations=n())

Get the total number of cars and taxis for each road cat with the same filters:使用相同的过滤器获取每只公路猫的汽车和出租车总数:

dat %>%
  filter(year == 1993,
         region_id == 'Wales') %>%
  group_by(road_catagory_id) %>%
  summarize(totCarTaxi = sum(cars_and_taxis)

There are many functions you can use to do calculations, look up more information on using dplyr here .您可以使用许多函数进行计算,请在此处查找有关使用dplyr的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM