Gaurav in the Valley

April 29, 2018

Naming Vectors in R, Part 2

What happens when you try and learn a new programming languages by only following half-baked tutorials, random YT videos, glossing over documentation, well ... doing almost everything but reading an actual book about the said programming language? You think you know how to solve a problem, albeit a simple one ... but you might not know (until some time has passed) how to solve that simple problem the right way.

Case in point, please see my blog Naming Vectors in R. Yes you can name Vectors in the manner I have described in that blog. But now that I'm taking Data Science: R Basics (highly recommended), I know that there's a super easy way to get the same result.

How?

Here's how:

Instead of the painstaking process I've outlined just to print the following out:

alt text

You could type the following simple one-liner in RStudio and get the same result:

hills_vector <- c("shivapuri"="north", "nagarjun"="north-west", "phulchowki"="south", "chandragiri"="south-west", "champadevi"="west")

Type that out in RStudio and see the following get printed out to the RStudio console:

alt text

Previous: Naming vectors in R