Loading...

Messages

Proposals

Stuck in your homework and missing deadline? Get urgent help in $10/Page with 24 hours deadline

Get Urgent Writing Help In Your Essays, Assignments, Homeworks, Dissertation, Thesis Or Coursework & Achieve A+ Grades.

Privacy Guaranteed - 100% Plagiarism Free Writing - Free Turnitin Report - Professional And Experienced Writers - 24/7 Online Support

Stat 350 purdue

19/12/2020 Client: saad24vbs Deadline: 7 Days

R Tutorial for Lab 1 Author: Leonore Findsen, Min Ren


1 STAT 350: Introduction to Statistics Department of Statistics, Purdue University, West Lafayette, IN 47907


0. Downloading Data You will have to download all of the data used from the internet before R can access the data. If the file is accessed via a link, then right click on the file name and save it to a directory on your hard drive. It can be difficult to find the files, so if you are unfamiliar with PCs, I suggest that you download it directly to the W drive (main campus drive). R cannot read a zipped file. Therefore, if any file is zipped, remember to extract it before you try to access it in R. Please remember where your files are stored so that you can access them for the labs.


1. General Information for R a) R uses functions to perform operations. To run a function with two inputs called


funcname, we type funcname(input1, input2). b) There is online help that is available. All you need to do is type “? command” at the ‘>’


command prompt and R studio will display the help file in a window. For example, “?setwd” at the ‘>’ prompt will open the available help documentation on utilizing the “setwd()” function. I also find that google is very effective if you are confused about a command.


c) The ‘#’ symbol/sign indicates a comment in R, i.e. everything to the right of the ‘#’ sign


will NOT be run as code. d) Data set names need to be one word (no spaces) and start with a letter. A common way to indicate a space is to use an underscore '_' or period '.'. Capitalization is important. Not all special characters can be used. Please change your table and variable names to match each situation. Points will be deducted if this is not done. e) Do not print out the whole data set inside of the program! We will take off points if there is code for this in your submission.


R Tutorial for Lab 1 Author: Leonore Findsen, Min Ren


2 STAT 350: Introduction to Statistics Department of Statistics, Purdue University, West Lafayette, IN 47907


e) RStudio: Once you open RStudio, you will see a window similar to what is provided below:


Fig. 1


Set working Directory I strongly suggest you set your default directory to where your data files are located. To accomplish this, navigate in the "Files" window (the lower right hand panel indicated by the blue arrow in Fig. 1) to the directory that you want. Then, Files → More → Set as Working Directory.


Create R Script file For your convenience, I recommend that you create a R script for each lab. To accomplish go to the red circled File (Fig. 1) → New File → R Script, then an “Untitled1” file will be created.


R Tutorial for Lab 1 Author: Leonore Findsen, Min Ren


3 STAT 350: Introduction to Statistics Department of Statistics, Purdue University, West Lafayette, IN 47907


You can use the small “save” button to save and change the name of “Untitled1” File.


Execution: Move your cursor to the beginning of the first line of code that you wish to run. Then click the Run button circled below. The cursor will automatically move down one line. If you want to run multiple lines, you may repeat this process. Alternatively, you may select all of the lines that you wish to run and then click on the Run button.


Import data Depending on the version of Rstudio, the procedure to import data may be considerably different. As we are unsure what version will be on the ITAP computers (or on your PC), we are including instructions for both. The older version is listed first and then the newer version. Each version will be separated by horizontal lines.


Older Version: In the right hand side of RStudio (red arrow in Fig. 1), you will find the Environment tab. Click import Dataset → From Local File … and this wizard will help you intuitively import the dataset and automatically display the data.


R Tutorial for Lab 1 Author: Leonore Findsen, Min Ren


4 STAT 350: Introduction to Statistics Department of Statistics, Purdue University, West Lafayette, IN 47907


When loading files from this class, be sure that you have the Heading setting at Yes. See the figure below for details.


Newer Version In the right hand side of RStudio (red arrow in Fig. 1), you will find the Environment tab. Click Import Dataset → From CSV …


Click Browse and navigate to where the file is saved. Make sure to check First Row as Names and Select Delimiter: Tab. Check the data preview to make sure everything looks good. You can also use the Name: Import option (lower left) to change the name R gives to the data set. I have chosen helicon. Then click Import.


R Tutorial for Lab 1 Author: Leonore Findsen, Min Ren


5 STAT 350: Introduction to Statistics Department of Statistics, Purdue University, West Lafayette, IN 47907


You can use “View” command to check your data manually. Note this starts with a capital 'V'. For example, “View(data)” This can also be accomplished by clicking on the 'View icon' which is circled in red in the diagram below. Please note all the variables will be displayed in the “Environment” window when you click the icon circled in green below.


Autocomplete In the RStudio, you can enjoy the “autocomplete” feature by hitting “Tab”. The prompt window will be like below:


R Tutorial for Lab 1 Author: Leonore Findsen, Min Ren


6 STAT 350: Introduction to Statistics Department of Statistics, Purdue University, West Lafayette, IN 47907


2. Importing Data sets, cleaning, manipulating, and printing them.


Hummingbirds and flowers. (Data Set: ex01-88helicon_m.txt) Different varieties of the tropical flower Heliconia are fertilized by different species of hummingbirds. Over time, the lengths of the flowers and the form of the hummingbirds’ beaks have evolved to match each other. Here are data on the lengths in millimeters of three varieties of these flowers on the island of Dominica:


When you import your data set, the name may be the name of the file (if you didn’t use the Name: option while importing). I strongly recommend that you change that name to something easier to type.


# this copies the dataset into another one with a shorter name


helicon <-ex01.88helicon_m


Please name your table in context. In this case, we are interested in Heliconia flowers, so I named the table helicon. Since capitalization is important, I often only use small letters. If you want to put a space in the name, use an underscore, _. This line will print out the entire data set. helicon


NEVER USE THIS COMMAND WHEN USING THE LAB DATASET; it is too big. Since it is important to look at your data after you import it to ensure that there are no problems, you can either use the View command or “head(tablename”) and" “tail(tablename)” which will print out the top and bottom rows of the data set. Unless explicitly stated, never print your data in your lab reports.


R Tutorial for Lab 1 Author: Leonore Findsen, Min Ren


7 STAT 350: Introduction to Statistics Department of Statistics, Purdue University, West Lafayette, IN 47907


I have highlighted the first five data points from the results from the View command. If you want to copy tables (or parts of tables) or graphs from the R output, I suggest that you use the Snipping Tool. You can also use that tool to highlight your answer. This is the procedure that I used in the above table. If you are just copying information from the console the Snipping Tool is not required. Lastly, in large data sets, it can be important to only print specific rows and variables. The following prints rows 2, 20, and 50 of the variables Length and Variety in that order. Be sure to have at least 2 variable names or the output is very confusing. > helicon[c(2,20,50),c("Length","Variety")]


Length Variety


2 46.75 bihai


20 43.09 red


50 36.66 yellow


Be sure that you include the "c" for each list and enclose all names in double quotes. (OPTIONAL) Assuming that helicon is in your current R session, run the following commands below and observe their outputs. Do not worry if you do not understand the output from each line as we are only currently attempting to build familiarity to R at this point in time.


head(helicon) tail(helicon) helicon[20:30, ] names(helicon) dim(helicon) class(helicon)


class(helicon[1, ]) class(helicon[ , 2]) class(helicon[ , 1])


summary(helicon[ , 2])


sum(helicon[ , 2])


R Tutorial for Lab 1 Author: Leonore Findsen, Min Ren


8 STAT 350: Introduction to Statistics Department of Statistics, Purdue University, West Lafayette, IN 47907


Cleaning and saving datasets Since many datasets have missing values, it is important to process them before beginning the analysis. For this class, we will simply remove those rows. The following command will remove rows that are not complete and then view the cleaned file. When you are viewing, be sure that you include the correct dataset name. helicon_cleaned <-helicon[complete.cases(helicon),]


View(helicon_cleaned)


Remember, the 'View' command has a capital V. Once you have cleaned the data set, you will want to save it so that you don't have to clean the data each time you use the data set. The procedure to save the new data set is as follows: write.table(helicon_cleaned,file="helicon_cleaned.txt",


row.names=FALSE, sep="\t")


This will write the file to your default directory. It is strongly recommended that you set your default directory (see above) to someplace that you can find easily. Manipulating data For readability, you might want to change the shortened name or abbreviation to the full version. This is done by the following commands: #Initialize a new variable by copying old values (which we’ll change)


helicon_cleaned$NewVariety <- as.character(helicon_cleaned$Variety)


# Change names


helicon_cleaned$NewVariety[helicon_cleaned$NewVariety =="red"]


<-"Caribaea_Red"


helicon_cleaned$NewVariety[helicon_cleaned$NewVariety =="yellow"]


<-"Caribaea_yellow"


View(helicon_cleaned)


#You can indicate a range of rows by using a colon (:)


#You have to include the comma (,) after the numbers if you want to


# include all of the variables in the original


orderhelicon_cleaned[c(36:43),]


The output of the last command is shown below: > helicon_cleaned[c(36:43),]


Variety Length NewVariety


36 red 38.23 Caribaea_Red


37 red 38.87 Caribaea_Red


38 red 37.78 Caribaea_Red


39 red 38.01 Caribaea_Red


40 yellow 36.78 Caribaea_yellow


41 yellow 37.02 Caribaea_yellow


42 yellow 36.52 Caribaea_yellow


43 yellow 36.11 Caribaea_yellow


R Tutorial for Lab 1 Author: Leonore Findsen, Min Ren


9 STAT 350: Introduction to Statistics Department of Statistics, Purdue University, West Lafayette, IN 47907


In addition, you might want to create a new variable based on mathematical operations from old variable(s). You can use the sample code below to convert the lengths of the beaks from millimeters to inches. The conversion factor is 1/25.4. helicon_cleaned$length_inches = helicon_cleaned$Length/25.4


head(helicon_cleaned)


> head(helicon_cleaned)


Variety Length NewVariety length_inches


1 bihai 47.12 bihai 1.855118


2 bihai 46.75 bihai 1.840551


3 bihai 46.81 bihai 1.842913


4 bihai 47.12 bihai 1.855118


5 bihai 46.67 bihai 1.837402


6 bihai 47.43 bihai 1.867323


You will see a new column in the data set called length_inches: Note that it is not necessary to create a new dataset variable. However, I strongly recommend that you do change it since (1) in case there’s a mistake, you won’t overwrite the original data, and (2) you can compare the new with the original. In addition, you should never re-use variable names. That is, your modified variable should always have a distinct name from any other variable in your data set. One final note: In Lab 2, we will be discussing different ways of referencing the data and the variables.


Applied Sciences

Architecture and Design

Biology

Business & Finance

Chemistry

Computer Science

Geography

Geology

Education

Engineering

English

Environmental science

Spanish

Government

History

Human Resource Management

Information Systems

Law

Literature

Mathematics

Nursing

Physics

Political Science

Psychology

Reading

Science

Social Science

Home

Blog

Archive

Contact

google+twitterfacebook

Copyright © 2019 HomeworkMarket.com

Homework is Completed By:

Writer Writer Name Amount Client Comments & Rating
Instant Homework Helper

ONLINE

Instant Homework Helper

$36

She helped me in last minute in a very reasonable price. She is a lifesaver, I got A+ grade in my homework, I will surely hire her again for my next assignments, Thumbs Up!

Order & Get This Solution Within 3 Hours in $25/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 3 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 6 Hours in $20/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 6 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 12 Hours in $15/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 12 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

6 writers have sent their proposals to do this homework:

University Coursework Help
Homework Guru
Top Essay Tutor
Helping Hand
Writer Writer Name Offer Chat
University Coursework Help

ONLINE

University Coursework Help

Hi dear, I am ready to do your homework in a reasonable price.

$102 Chat With Writer
Homework Guru

ONLINE

Homework Guru

Hi dear, I am ready to do your homework in a reasonable price and in a timely manner.

$102 Chat With Writer
Top Essay Tutor

ONLINE

Top Essay Tutor

I have more than 12 years of experience in managing online classes, exams, and quizzes on different websites like; Connect, McGraw-Hill, and Blackboard. I always provide a guarantee to my clients for their grades.

$105 Chat With Writer
Helping Hand

ONLINE

Helping Hand

I am an Academic writer with 10 years of experience. As an Academic writer, my aim is to generate unique content without Plagiarism as per the client’s requirements.

$100 Chat With Writer

Let our expert academic writers to help you in achieving a+ grades in your homework, assignment, quiz or exam.

Similar Homework Questions

Fartlek training program example - A cantilever beam is loaded as shown - Radioactive dating game lab worksheet answers - How does toyota market their products - Quine truth by convention - Advocating for the Nursing Role in Program Design and Implementation - The “four ps” to consider in choosing a financial institution include product, price, people, and - Why do amides have higher boiling points than carboxylic acids - Please see attachment - The walt disney company the entertainment king case analysis - The great bear libby gleeson youtube - Supplementary services in service marketing - There are different types of accountants (corporate accountants, auditors, tax accountants, etc.) - Where is b43 postcode - Water cycle carbon cycle nitrogen cycle worksheet - +91##_9928097710 lovE maRRiaGE specialist Molvi ji in Mumbai - Homework - Chapter 31 health assessment and physical examination - Andersen door hinge adjustment instructions - Twin oaks health center has a bond issue outstanding - Compilation of separate clips in a film crossword - Boiling point of ch3br - Gloucester royal hospital women's centre - Celebrating diversity in early years - Intel processor transistor count chart from 1971 to 2015 - Letter from birmingham jail pathos essay - Ndis participant portal sign in - Writing tutor wesleyan - Alpha c chiang mathematical economics solution - Inform - Oodgeroo noonuccal we are going - Internet Marketing - The stroll dance in grease - Alpha to omega placement test - Film the secret of roan inish - Supply chain - How does vmware cross cloud architecture address incompatibility between clouds - Ehwic 4g lte a - Difference between radio and television news - Compare and contrast two mental health theories - Electrolux and ge appliances case study - The crucible and the dressmaker prompts - Dns method for enzyme assay - Why doesn t romeo want to fight tybalt at first - Just a dream chris van allsburg activities - Culturally diverse groups in australia - Identity and Access Management - What does figure weights measure on the wisc-v - 2 robyn court hampton park - Gauss divergence theorem examples - Next week super discount airlines has a flight - Do not stand at my grave and weep poem words - Is mass marketing dead debate - Professional ethics and responsibilities of intermediaries - Www exploratorium edu memory index html - Focused vs diffused thinking - Whiston hospital gynaecology consultants - Social work evaluation enhancing what we do - Rent seeking microeconomics - N492 Assignment Mod 2: - Lab 1 introduction to science exercise 7 - What is an example of a folktale story - Landgate power of attorney form - Zadie smith in conversation - Persuasive speech preparation outline - Hy dairies case study analysis - Vce study score bell curve - Separation of powers texas constitution - Ex 6 1 determining gross profit - Universal mca music publishing - Corpus ergo air cushion - Describe the importance of effective communication in the correctional setting - American History Paper - I need 700 words summary Journal of World Business - BUSINESS LAW, ETHICS, AND SOCIAL RES - Five business level strategies examples - J watson strategy an introduction to game theory norton 2002 - Ncea level 2 biology cells - Why is eggshell a good material for edta to chelate - Beyond culture 1976 by edward t hall iceberg - Chemistry year 7 quiz - Washington state university chemical engineering - In the needs assessment process organizational analysis deals with identifying - Human cheek cell diagram - Healthcare Economic Week 1 Project - A dry cleaner uses exponential smoothing to forecast equipment - Intro to Public Administration - Byte stuffing in java - Critical Analyses - Acculturation - 6.5 Strategic Thinking Project - Super size me answers - Essential elements of a contract in business law - Secret key encryption lab - Appraisal Form - Advantages and disadvantages of finite difference method - Telephone collection call scripts - Which type of muscle tissue has cells that branch - Order of rotational symmetry of all alphabets - Strack martin stepper 1988 pen in mouth