1. Create two vectors named v1 and v2, where v1 is the sequence of integers from 2 to 6, and v2 is the sequence of integers from 5 to 9.
v1=c(2:6)
v1
## [1] 2 3 4 5 6
v2=c(5:9)
v2
## [1] 5 6 7 8 9
productv=v1%*%v2
productv
##      [,1]
## [1,]  150

b.What is v2 minus v1?

minusv=v2-v1
minusv
## [1] 3 3 3 3 3

c.What is the inner product of v1 and v2?

productv=v1%*%v2
productv
##      [,1]
## [1,]  150

d.Replace the elements in v1+v2 that are greater than 10 with the number 0. Show that vector.

sumv=v1+v2
sumv[which(sumv>10)]=0
sumv
## [1] 7 9 0 0 0
  1. Create a 5 by 5 matrix with the numbers 1 to 25 as its elements, and call it m1.
m1=matrix(1:25,nrow=5)
m1
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    6   11   16   21
## [2,]    2    7   12   17   22
## [3,]    3    8   13   18   23
## [4,]    4    9   14   19   24
## [5,]    5   10   15   20   25
  1. What is m1 times v1?
m1v1=m1%*%v1
m1v1
##      [,1]
## [1,]  270
## [2,]  290
## [3,]  310
## [4,]  330
## [5,]  350

c.What is v1 times m1?

v1m1=v1%*%m1
v1m1
##      [,1] [,2] [,3] [,4] [,5]
## [1,]   70  170  270  370  470

d.What is m1 times the transpose of m1?

m1trm1=m1%*%t(m1)
m1trm1
##      [,1] [,2] [,3] [,4] [,5]
## [1,]  855  910  965 1020 1075
## [2,]  910  970 1030 1090 1150
## [3,]  965 1030 1095 1160 1225
## [4,] 1020 1090 1160 1230 1300
## [5,] 1075 1150 1225 1300 1375

3.Create a date frame with at least five rows and three columns. The first variable (column) should be dates, the second variable should be strings (characters), and the third variable should be numbers. Name each variable something appropriate and short.

v1=c(2:6)
v2=c(5:9)
m1=matrix(1:25,nrow=5)
getwd()
## [1] "C:/Users/monabiyan/SkyDrive/Summer 2015/Statistics/HW1"
setwd("C:/Users/monabiyan/SkyDrive/Summer 2015/Statistics/HW1")
getwd()
## [1] "C:/Users/monabiyan/SkyDrive/Summer 2015/Statistics/HW1"
df1<-data.frame(c("2015-05-19","2015-05-19","2015-05-19","2015-05-19","2015-05-19"),c("Mason","Kati","Sara","David","Jack"),c(80,90,95,100,50))
colnames(df1)<-c("Submission_Date","Name","Grade")
df1$Submission_Date<-as.Date(df1$Submission_Date)
df1$Name<-as.character(df1$Name)
df1$Grade=as.numeric(df1$Grade)
str(df1)
## 'data.frame':    5 obs. of  3 variables:
##  $ Submission_Date: Date, format: "2015-05-19" "2015-05-19" ...
##  $ Name           : chr  "Mason" "Kati" "Sara" "David" ...
##  $ Grade          : num  80 90 95 100 50
write.table(df1,file="df1.csv",row.names=FALSE,sep=",")
df1 <- read.table(file="df1.csv",header=TRUE,sep=",",stringsAsFactors=FALSE)
str(df1)
## 'data.frame':    5 obs. of  3 variables:
##  $ Submission_Date: chr  "2015-05-19" "2015-05-19" "2015-05-19" "2015-05-19" ...
##  $ Name           : chr  "Mason" "Kati" "Sara" "David" ...
##  $ Grade          : int  80 90 95 100 50
df2=df1[c(1,3,5),c(1,2)]
df2
##   Submission_Date  Name
## 1      2015-05-19 Mason
## 3      2015-05-19  Sara
## 5      2015-05-19  Jack
df1[df1[1:5,3]%%2==0,3]=0
df1
##   Submission_Date  Name Grade
## 1      2015-05-19 Mason     0
## 2      2015-05-19  Kati     0
## 3      2015-05-19  Sara    95
## 4      2015-05-19 David     0
## 5      2015-05-19  Jack     0
list1=list(v1,v2,m1,df1)
names(list1) <- c("vector1","vector2","matrix1","data_frame")
str(list1)
## List of 4
##  $ vector1   : int [1:5] 2 3 4 5 6
##  $ vector2   : int [1:5] 5 6 7 8 9
##  $ matrix1   : int [1:5, 1:5] 1 2 3 4 5 6 7 8 9 10 ...
##  $ data_frame:'data.frame':  5 obs. of  3 variables:
##   ..$ Submission_Date: chr [1:5] "2015-05-19" "2015-05-19" "2015-05-19" "2015-05-19" ...
##   ..$ Name           : chr [1:5] "Mason" "Kati" "Sara" "David" ...
##   ..$ Grade          : num [1:5] 0 0 95 0 0
list1$matrix1[2,1]
## [1] 2
  1. Using latex equation notation in your .Rmd file, write out the quadratic formula, so that in your html file it looks pretty and like the version we all learned in high school. (Eg, see the box in the top right of this wikipedia page: http://en.wikipedia.org/wiki/Quadratic_equation.)

\[\frac{-b\pm \sqrt{b^2 - 4ac}}{2a}\]