Discovering Data
  • Home
  • Blog

Using R to investigate footfall data

11/9/2015

0 Comments

 
The raw data (for Leeds City Centre) is available here. A network of CCTV cameras is used to track the number of people passing through an area per hour. The data is provided in the form of csv files. As an example I am taking one file for September 2014. I wrote and ran the R commands on the command line rather than in RStudio.

The first step is to read the data into memory. Since I saved the data file in my working directory (you can get this using the function getwd()) I can just use the read.csv() function and pass in the name of the file:

myData <- read.csv("monthly-data-feed-sept-2014-20141009.csv")
The next step is to extract the data just for one location, in this case the data for Briggate
brigData <- myData[myData$LocationName == "Briggate",]
Then I can narrow this data down to Monday
brigData_Mon <- brigData[brigData$Weekday == "Monday",]
The data can now be plotted:
plot(brigData_Mon$Hour, brigData_Mon$InCount)
Picture

Pedestrians per hour, Friday (Sep 2014)

I produced similar charts for the other days of the week. R can also produce summary statistics for the data
Day Max Time of Max Min Time of Min Mean to nearest whole number
Mon 5144 13 38 4 1484
Tues 4701 13 25 4 1400
Wed 4733 13 66 2 1454
Thur 4650 13 49 4 1507
Fri 5477 13 132 5 1793
Sat 8271 15 157 6 2388
Sun 5623 14 115 7 1469
Summary data such as max and min values for particular days can be obtained from:
max(brigData_Mon$InCount) and min(brigData_Mon$InCount)
0 Comments

    This blog includes:

    Scripts mainly in Python with a few in R covering NLP, Pandas, Matplotlib and others. See the home page for links to some of the scripts.  Also includes some explanations of basic data science terminology.

    Archives

    October 2018
    June 2018
    April 2018
    June 2017
    April 2017
    March 2017
    February 2017
    January 2017
    November 2016
    September 2016
    July 2016
    June 2016
    May 2016
    November 2015
    November 2014

    RSS Feed

Proudly powered by Weebly
  • Home
  • Blog