Basics in R Flashcards
Simple calculations
> 5 + 3
Variable assignment
> age < - 28
Using existing functions for calculations
> sqrt (225)
Creating a vector
> weekly_sales < - c(200, 120, 130, 125, 220)
Getting information out of a vector
> weekly_sales{3}
> weekly_sales{weekly_sales > 180}
Installing packages
> install.packages(“somepackage”)
Loading packages
> library(“somepackage”)
Setting working directory
> setwd(“~/myDirectory”)
To get the symbol, Alt 126
Reading a csv file
> data < - read.csv(“somedata.csv”)
Get the structure of the object
> str(data)
Get the head of the object
> head(data)
Get the names of the object
> names(data)
Get the entire object
> data
Calculate the mean of a variable
> mean(data$someVariable)
Calculate the median of a variable
> median(data$someVariable)