Tech Junkie Blog - Real World Tutorials, Happy Coding!: R Programming: Variables

Thursday, May 17, 2018

R Programming: Variables

R is a programming language that is a little different in syntax then your typical mainstream languages like Java or C#. In this post we will go over how to create variables in R.

Let's create some variables about a user:

To create a variable in we use the <- key for example if you want to assign a value to variable firstName, you would write firstName <-  "John" or "John" -> firstName












If you type in the firstName in the console you will "John" as the value









To get the type of the variable you can use the class(firstName)











As you can see the variable firstName has the type character

Now let say you created a new variable call zipCode and you want to convert to a string.  You can do that with the "as" method first lets create the zipCode variable with the statement zipCode <- 90210





Now let's see what the type of zipCode is by using the class method class(zipCode)









Let's convert the zipCode variable to the character type by using the "as" function like the following

zipCode <- as.character(zipCode)


1 comment:

Search This Blog