Beginning with R — The uncharted territory

Beginning with R — The uncharted territoryPuneet SharmaBlockedUnblockFollowFollowingJul 3Coming from a non-programming background and python being the first exposure to programming and data analysis, trying to get my hands dirty in R seemed pretty daunting at first.

R at times can feel a bit peculiar and unique since it is based on the premise of doing data analysis and statistics rather than software programming which is the case with python.

But as I push myself and try to learn the many quirks and leverages of R over python, it sort of gives a different perspective of doing data analysis.

Plus, there is a strong edge of using R over python — the vast and contemporary libraries of various statistical methodologies being implemented in R by statisticians world over.

Besides its quirks, the most interesting IDE developed so far for R — Rstudio , makes doing data analysis seem like fun activity.

The various other things in Rstudio like making reports with support of LaTex and HTML and making static websites using HUGO is something which makes life quite easy.

But to be able to do all this cool stuff we need to first grasp the basics of R which are the building blocks of any complex data analysis pipeline.

4" "hello" "TRUE" "FALSE"As we can see, a vector can have any data type, be it number, character or boolean.

But we notice something.

All the elements in the vector are coerced to character type because the vector contains a string "hello".

This is the effect of implicit coercion.

For strictly making a numeric vector, use vector() function.

## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0We can use such a vector to preallocate a vector which can be used for appending values from a for loop which is faster than appending values to an empty vector since every time a value is appended in an empty vector, R makes a copy of it thus slowing the whole process.

Coercion — Objects like vectors, data frames etc.

can be coerced to different classess using as.

class function.

## [1] "numeric"## [1] "character"## [1] "logical"MatricesMatrix is same as a vector except it has an additional attribute of dimension.