Assignment for session 2
A1: To bind columns /rows from two different matrices into one new matrix
Soln: Matrix 1 assignment and generation.
mat1<-c(1:9)
dim(mat1)<-c(3,3)
Matrix 2 assignment and generation
mat2<-c(32,48,1,5,10,12,15,18,23)
dim(mat2)<-c(3,3)
Now binding column 3 of mat1 with column 1 of mat 2
selecting column 3 of mat1: x<-mat1[ ,3]
selecting column 1 of mat2 :y<-mat2[ ,1]
Binding column 3 of mat1 and column1 of mat2 into z: cbind(x,y)
A2: Multiply two matrices
Soln: mat1%*%mat2
A3:To read NSE historical data from 01/12/2012 to 31/12/2012 from a .csv file.
To find regression between the high price and opening share price and also calulate the residuals
Soln: Command to load the file:
>nse<-read.csv(file.choose(),header=T)
> nse
Command for regression:
> open<-nse[ ,2]
> high<-nse[ ,3]
> reg<-lm(high~open,data=nse)
> reg
command
for residuals:
>residuals(reg)
>residuals(reg)
A4:To generate data for a normal distribution and plot the distribution curve
Soln:
>x<-seq(0,200)
>y<-dnorm(x,mean=100,sd=20)
>plot(x,y,type="l",col="red")
No comments:
Post a Comment