You may collaborate with other students when completing this assignment.
Create a new script file. The first several lines should be:
# NAME: <<your-name-here>>
# STUDENT ID: <<your-id-here>>
# COLLABORATORS: <<list names of collaborators>>
set.seed(7125) # initialize random number generator
In your script, perform the following operations:
var1
and var2
var1
and var2
in a data frame named
myData.df0
var1
, var2
, and
myData.df0
in a single data file on your
computermyData.df0
var1
and var2
score 1
and score 2
,
respectively# NAME: <<your-name-here>>
# STUDENT ID: <<your-id-here>>
# COLLABORATORS: <<list names of collaborators>>
set.seed(7125) # initialize random number generator
# - create two sets of 50 normal random numbers with means of 40 and standard deviations of 6
# - save the two sets of numbers in variables named `var1` and `var2`
var1 <- rnorm(50,40,6)
var2 <- rnorm(50,40,6)
# - put `var1` and `var2` in a data frame named `myData.df0`
myData.df0 <- data.frame(var1,var2)
# - save `var1`, `var2`, and `myData.df0` in a *single* data file on your computer
# save(var1,var2,myData.df0,file="theDataFileName.rda")
# - calculate the mean, min, and max for the variables in `myData.df0`
sapply(myData.df0,mean) # mean for each variable
## var1 var2
## 41.61795 39.84187
sapply(myData.df0,range) # range [min,max] for each variable
## var1 var2
## [1,] 29.16996 25.42608
## [2,] 54.11855 51.69011
# alternative 1:
summary(myData.df0)
## var1 var2
## Min. :29.17 Min. :25.43
## 1st Qu.:36.61 1st Qu.:36.17
## Median :41.56 Median :40.41
## Mean :41.62 Mean :39.84
## 3rd Qu.:46.46 3rd Qu.:43.68
## Max. :54.12 Max. :51.69
# alternative 2:
mean(myData.df0$var1)
## [1] 41.61795
mean(myData.df0$var2)
## [1] 39.84187
range(myData.df0$var1)
## [1] 29.16996 54.11855
range(myData.df0$var2)
## [1] 25.42608 51.69011
# - create a scatter plot of `var1` and `var2`
# - make sure the x and y axes have the same scale
# - add a dotted identity line (i.e., x=y)
# - name the x and y axes `score 1` and `score 2`, respectively
LimMin <- min(c(range(myData.df0$var1),range(myData.df0$var2)))
LimMax <- max(c(range(myData.df0$var1),range(myData.df0$var2)))
plot(x=myData.df0$var1,
y=myData.df0$var2,
xlim=c(LimMin,LimMax),
ylim=c(LimMin,LimMax),
xlab="score 1",
ylab="score 2")
abline(a=0,b=1,lty=3) # add identity line
# - upload your script onto Avenue 2 Learn