Plant & Soil Sciences eLibraryPRO
control panel control panel

Correlation Using the R Statistical Package - Part 2: Data Preparation

Rate Me

A Few R Data Types

Every computer programming environment (i.e. R, SAS, SPSS, Python, Perl, etc.) offers various data types. Data types are variables that are used during the run time (when a computer progam is running) to hold a value or obtain the current value from the variable. For example let's say we are wanting to run an analysis for a farm which grows apples, peaches, strawberries and raspberries.  In the analysis, we may want to hold an integer value in a computer program where this integer value signifies the number of fruits we packed in the last box (i.e. how many apples, etc.); similarly we may want to hold a string value in the same computer program that signifies the name of the fruit we packed in the last box (i.e. apples), etc.  Accordingly an integer and a string are two of the common data types offered in many programming environments such as Python and Perl. Every programming environment offers multitude data types, in this topic we will review the three most common data types offered by R: vectors, list and tables.

Presentation on demonstrating data types in R , by Ashu Guru, Univ of Nebraska Raikes School (15 mins)

[Download Video] (You may right click and save as)

Click here to download the PDF of slides used

Click here to download the source of the R script used in the talk

Click here to download an example data file that may be used along with the Script


Question : A "Vector" variable in R can hold a series of values of a given type (say Integer)




Question : If we have an R "Vector" defined by the statement:

aQuestionVector <- c(13,12,5,8,15)

What does the notation aQuestionVector[3] refer to?



Question : We know that a R "List" may be visualized as a Vector of Vectors - Can the individual Vectors inside a list have different sizes (i.e. number of cells)?





We have found it to be much easier to learn these concepts if you have the opportunity to practice with some data.  Let's start with some simple excercises to help you practice.  

Exercise 1

Write a script in which you have defined a vector with 5 cells having values 2,4,8,16, and 32. Next write an instruction with a new variable that will calculate the value of the sum of all the integer values of the defined vector. Finally print the sum from the variable.

Answer: You must get an output of 62 on the R console i.e. the lower left frame of RStudio.


Exercise 2

Modify the input data file for the Vector Table (from the data file link above the video tutorial) and change the column names to GroupingVariable, Att1, Att2 instead of GroupOn,Attribute1,Attribute2 respectively. Now print the vector form for the column 1 of the table.




Be the first to write a comment...

Control Panel cancel

Create activities for your moodle courses. Moodle Go to moodle
Select and group e-Library Lessons to create your own package... My Communities
Community Blogs Community Media

My Joined Communities

My Blogs - a journal of my thoughts... My Blogs
My Comments - my thoughts expressed as a feedback... My Comments
Classes that I am taking Registered Classes
Class Blogs Class Media
Check the scores of assesments that you have taken Taken Assessments
Please confirm your selection.