联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> CS作业CS作业

日期:2018-09-26 10:13

mpgLab Assignment 2

For this assignment you will be submitting a R script file with R commands/comments and a Word File that captures output and answers some questions.

1. Create a subdirectory on Desktop called: Lab2Practice

2. Copy the following to files into it (both should be in Lab2 subdirectory):

mpgdata.csv

boston_corrected.csv

Mpgdata file:

#The file mpgdata.csv contains data concerning city-cycle fuel consumption in miles per gallon.

#There are 398 elements in the dataset

#Each element is described by 9 variables

#    1. mpg: vehicle mpg:        continuous

#    2. cyl:engine cylinder count:multi-valued discrete

#    3. displacement: engine displacement:  continuous

#    4. horspower: engine horsepower:    continuous

#    5. weight: vehicle weight:  continuous

#    6. acceleration:  vehicle acceleration:continuous

#    7. modelYR:    model year:multi-valued discrete

#    8. origin:vehicle origin:         multi-valued discrete (coded)

#    9. carName:      car name:text (unique for each instance)


R Script File 1:

Within R set up script file with following header

#Lab 2 review MPG

#Your name

All of the following should be typed documented with comments within the script file. Please test. If having difficulty make a note in comments and capture a screen shot an put in word file.

Recommended procedure: type in lines, select lines, and send to console. If errors adjust.

1.Set working directory to: Lab2Practice

2.Check working directory

3.Load file into variable called: mpgdata

4.Display contents of mpgdata on screen

5.Calculate Mean mpg using sum (x) and length (x) assign to new variable called mpg_mean

6.Display contents of mpg_mean on screen

7.Calculate min and max values for modelYR

8.Sort carName variable and save to new variable called carsort (hint: remember it is part of “dataframe”)

9.Use table function to count instances of origin, assign to variable called origin.count

10.Display origin.count  on screen.

11.Sort origin.count, decreasing and assign to variable called origin.count_s  Hint: decreasing=TRUE

12.Display origin.count_s on screen, you should see a different order than previous!

Also note, that the values are coded and you need more information to translate what the categories are!

We didn’t go over a plotting example in detail and we will go into more detail next week but give it a try: (you can use simplest version of command)

13.Type help command for getting information about barplot command

14.Take screen shot of browser result and put in Word file.

15.Use barplot command to plot orgin.count_s, add xlab= “Origin”, ylab=”Count)

16.Take a screen shot of resulting graph and put in Word file

17.Use the basic hist command to plot mpg, in comments indicate how breaks are set (hint use help to try find information). Note: you are not setting breaks just finding out what default is.

18.Take a screen shot of resulting graph and put in Word file

19.Use plot to show relationship of displacement (x) versus horsepower (y)

20.Take a screen shot and put in Word File

21.Save Script file to a file called: lab2_yourintials.  (file will have a default extension of R)

22.Take a screen shot of Lab2Practice Directory and put into Word File

23.Using File->Source R code, load file –BostonAnalysis_small.R

In Word answer the following: a. what happens when you use this command? b. how many graphs did it plot?

24.Use File->Open Script, load file – BostoanAnalysis_small.R

Within R editor look at file.

In Word answer the following: how many separate plots did the script do?

25.Select each section of “plotting code” from script and run in console.

Take a screen shot of one and put in Word Document.

26.Looking at the variables described for the mpgdata (listed at top), identify the types of plots that could be done based on type of variable (list in Word document)


Save the Word Document: Lab2_yourname.docx

Submit: Your R script and word document to Lab 2 submission point in Moodle.

Remember to copy your lab2 and lab2practice folders back to your personal drive.





What we did today:

Lab 2 Practice

####################################

## Lab 2 Practice

## Sept. 9. 2014

## Created by Erin McLean

####################################


### Examples of how to use the c() function

An_Rain_cm<- c(71,48,32,28,129,18,8)

c(71,48,32,28,129,18,8)

An_Rain_cm=c(71,48,32,28,129,18,8)

assign("An_Rain_cm", c(71,48,32,28,129,18,8))


###Manually assigning a data frame

ClimStat<-c('A','B','C','D','E','F','G')

Days<-c(114,42,54,32,41,26,3)

An_Rain_cm<- c(71,48,32,28,129,18,8)

An_Rain_mm<- c(710,480,320,280,1290,180,80)

Raindata<- data.frame('ClimStat', 'Days', 'An_Rain_cm', 'An_rain_mm')

names(Raindata)<- c("Climate Station", "Days with Precipitation",

"Annual Rinfall(cm)", "Annual Rainfall(mm)")


###Setting a working directory

setwd('C:\\Users\\Erin\\Documents\\Geog2700Lab')

getwd()

###Loading a CSV file

raindata<-read.table(file="Lab1.csv", head=TRUE, sep=",")

raindata

#Checking assigned variables

ls()


## Finding the mean

mean(An_Rain_cm) ##Shoud get 47.71429


## Referencing within a dataframe

raindata$ClimStat


## Basic functions

max(An_Rain_cm) #Should be 129

min(An_Rain_cm) #Should be 8

range(An_Rain_cm) #Should be 8 129

length(An_Rain_cm) #Should be 7

sum(An_Rain_cm) #Should be 334

prod(An_Rain_cm) #Should be 56723079168

mean(An_Rain_cm) #Should be 47.71429

var(An_Rain_cm) #Should be 1707.571

sort(An_Rain_cm) # Should get 8 18 28 32 48 71 129


###Assigning Data Part 2 + Mathematic Operators

x<-c(1)

y<-c(1)

z=x+y

z #You should get 2




##Calculating mean from Lab 1 example

mean_days=sum(raindata$Days)/length(raindata$Days)

mean_days  #Should get 44.57143


mean(raindata$Days) #Should be the same 44.57143


###Functions that create data


n<-10

1:n-1 #Should see [1] 0 1 2 3 4 5 6 7 8 9


## Plotting Data

help(hist)


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp