http://uit.unt.edu/research

Data Science and Analytics

UITHelp Desk | Training | About Us | Publications | DSA Home

Please participate in the DSA Client Feedback Survey.

Back to the Do it yourself Introduction to R

4.) Some initial orientation to using R. There are some key terms you will need to become familiar with; first R is an object oriented system. Anything can be an object; a score, a series of scores (also called a vector), a named variable (also called a vector), a matrix (made up of rows and columns), a data frame, or a list (a larger group of objects). As an example; lets open R and create a new object called ‘x’. Our object x will initially be something as simple as an individual score, say 5. To communicate this in R, in the console type the following and hit the enter key at the end of each line:

x <- 5

x = 5

x<-5

x=5

x

Notice how both = and <- refer to the same operation and the presence of spaces before and after are not necessary. The operation = and <- perform is assignment; in other words, we have assigned 5 to x. Now we can perform simple arithmetic or complex algebra using our assigned value for x. For example, try any of the following:

x + 5

x - 5

x / 6

x ^ 2

x ^ 1/2

x * 6

x6

6x

Notice above that x * 6 is functional, while 6x and x6 are not.

x^2 + 5 * x - (x)

5 * x * (x^2)

5 * (x * x)^2

We can also assign a group of values to our object using the concatenate or combine function which as a default produces a vector. We can then assign our vector (x) to another object or use it in a more complex function.

x <- c(5, 6, 7, 9, 10, 4, 5)

x

x + 2

is.vector(x)

is.numeric(x)

y <- x * 2

y

You can continue to explore the arithmetic functions of R, but I’m sure you didn’t come to learn how R can be used as a calculator, so let’s continue to the next module.

* Nifty trick in R console type: demo(graphics) then continue slowly hitting the enter key until nothing happens.

Back to the Do it yourself Introduction to R

Please participate in the DSA Client Feedback Survey.

Contact Information

Jon Starkweather, PhD

Jonathan.Starkweather@unt.edu

940-565-4066

Richard Herrington, PhD

Richard.Herrington@unt.edu

940-565-2140

Last updated: 2018.11.06 by Jon Starkweather.

UITHelp Desk | Training | About Us | Publications | DSA Home