Git Product home page Git Product logo

getdata_project's Introduction

run_analysis.R

Preparation

On top of basic R environment, your R must have:

  • plyr package
  • reshape2 package

The data we use can be downloaded from:

So basically, you just git clone this script git, and download the data from the location above. Here's the typical example command flow to run the script:

$ git clone <URL-to-this-git>.git scriptdir
$ wget https://d396qusza40orc.cloudfront.net/getdata%2Fprojectfiles%2FUCI%20HAR%20Dataset.zip
$ unzip *.zip
$ cp scriptdir/run_analysis.R UCI\ HAR\ Dataset
$ cd UCI\ HAR\ Dataset
$ R

> source("run_analysis.R")

Script overview

The analysis is divided into 6 steps.

  • Step 0: Read files from local directory and store them in RAM memory as data.frame

    • The definition of each file is found in UCI\ HAR\ Dataset/README.txt.
  • Step 1: Combine the two datasets, "test" and "train", into one dataset called 'merged'

    • In this step, the column names are also set by reading features data.frame in the second column.
  • Step 2: As we examin only the mean and std values, only the corresponding columns are fultered.

  • Step 3: Map the activity number (1-6) to the name defined in activitylabels data.frame.

  • Step 4: Make the column name of each variable more meaningful and better suited for R.

    • Remove the 't' character at the beginning as it does not hold special meaning in our analaysis.
    • Replaced 'f' with FFT to mean Fast Fourier Transformation
    • Do not use abbreviated words such as 'Acc' and 'Mag'
    • Do not use - and () as they can lead to some R unexpected behavior.
  • Step 5: Melt the data once, and reshape the data in a tidy format.

    • As the data.frame now is too wide and hard to get the tidy result, the data.frame is made in a tall form by melt function from reshape2 library. This resulted melted table is easier to deal with; we can use dcast to reshape the data. The resulted casted table is yet unordered like 1, 10, 11, 20, 2..., it must be reordered by factor and arrange function from plyr package.

getdata_project's People

Contributors

yiu31802 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.