R
R Beginners Functions
R is another open source programmer language, inspired from S language which was written for Statistician who wanted to do Data Analytics and Data Science.
Here are some beginner functions you can use to write start working with.
-
getwd()to check there current working directory -
setwd("~/Desktop/")to change the current working directory location -
dir()to check the files in that directory. -
corarrayfns to create an array -
rbindto combine two arrays -
sortto sort values -
seqto generate numbers in a range(range fns in Python) -
which.maxreturns the index of the max element in the array -
data.frameto create a data frame from arrays -
read.csvto create a data frame from csv -
write.csv(WHO_Europe, "WHO_Europe.csv”)to save the file -
matchis like a counting no.of times a value occurred in a column -
as.numericto convert boolean/logical operator values to numeric
some constants
-
NA : Not Available (i.e. missing values)
-
NaN : Not a Number (e.g. 0/0)
-
Inf: Infinity
-
-Inf : Minus Infinity.
dataframe
-
namesto print all the column names in a data frame -
$to check a data frame each column’s values -
dimto check the shape of the data frame -
strto check the structure/type of object/variable -
summaryto check summary of data frame -
subsetto filter the required data. -
tableis like summary of a categorical variables -
tapply(WHO$Over60, WHO$Region, max)is like pivot -
tapply(WHO$LiteracyRate, WHO$Region, max, na.rm=TRUE)excluding the NA’s
Check/remove Locals variables
-
ls()to check all local variables -
rm(..)to remove variables
__Plotting __
-
histto do histogram plots -
plotfor scatter plots/ linear plots -
boxplot(WHO$LifeExpectancy ~ WHO$Region)to box plot Life Expectancy for each region- internal optional labels are
xlab,ylab,name
- internal optional labels are
Date/Format
-
as.Date(strptime(, "%m/%d/%y %H:%M”))to convert string into Date Type -
formatto convert strings into string
BUILT-IN FUNCTION
- http://www.statmethods.net/management/functions.html
EXAMPLES:
- https://en.wikibooks.org/wiki/R_Programming/Sample_Session
MAP, REDUCE, FILTER, FIND, NEGATE:
- http://www.johnmyleswhite.com/notebook/2010/09/23/higher-order-functions-in-r/
Sample Data Files:
-
https://d37djvu3ytnwxt.cloudfront.net/assets/courseware/v1/ccdc87b80d92a9c24de2f04daec5bb58/asset-v1:MITx+15.071x_3+1T2016+type@asset+block/WHO.csv
-
https://d37djvu3ytnwxt.cloudfront.net/assets/courseware/v1/3ef78a720083c74cd2649289a475158d/asset-v1:MITx+15.071x_3+1T2016+type@asset+block/USDA.csv