Starting with R

Loiyumba

What is R?

  • is an open-source statistical software package
  • can do data analysis
  • can visualize data
  • can fit machine learning models

To download R - https://cran.r-project.org/

What is RStudio?

  • is the most popular open source integrated development environment(IDE) for R
  • can create interactive plottings
  • can create web applications
  • can create presentations
  • can write documents, publishing, etc

To download RStudio - https://www.rstudio.com/products/rstudio/download/

RStudio

RStudio comes with 4 panes -

  • Source/Editor
  • Console/Command line
  • Environment/History/Files
  • Plots/Packages/Help/Viewer
  • And many other functions
guess <- 220000000
class(guess) <- c("POSIXct", "POSIXt")
guess
[1] "1976-12-21 12:36:40 IST"
guess <- as.POSIXlt(guess)
names(unclass(guess))
 [1] "sec"    "min"    "hour"   "mday"   "mon"    "year"   "wday"  
 [8] "yday"   "isdst"  "zone"   "gmtoff"
guess$wday
[1] 2
now - guess
Time difference of 14441.02 days

Dates come in different style. In order to work with it, we use strptime() function. Do ?strptime

dates <- c("December 25, 2014 11:45", "January 25, 2015 23:30")
dates
[1] "December 25, 2014 11:45" "January 25, 2015 23:30" 
class(dates)
[1] "character"
new_dates <- strptime(dates, format = "%B %d, %Y %H:%M")
class(new_dates)
[1] "POSIXlt" "POSIXt" 
first_date <- as.Date("1996-09-28")
second_date <- as.Date("1996-10-15")
second_date - first_date
Time difference of 17 days