#Matrix
A<-matrix(c(1,2,3,4,6,7,8,9,0), nrow=3, ncol=3);
print(A)
## [,1] [,2] [,3]
## [1,] 1 4 8
## [2,] 2 6 9
## [3,] 3 7 0
A<-matrix(c(1,2,3,4,6,7,8,9,0), nrow=3, ncol=3, dimnames=list(c("X","Y","Z"), c("A","S","D")))
print(A)
## A S D
## X 1 4 8
## Y 2 6 9
## Z 3 7 0
attributes(A);
## $dim
## [1] 3 3
##
## $dimnames
## $dimnames[[1]]
## [1] "X" "Y" "Z"
##
## $dimnames[[2]]
## [1] "A" "S" "D"
class(A);
## [1] "matrix" "array"
colnames(A);
## [1] "A" "S" "D"
rownames(A);
## [1] "X" "Y" "Z"
B<- rbind (A, c(1,2,3),c(4,5,6));
print(B);
## A S D
## X 1 4 8
## Y 2 6 9
## Z 3 7 0
## 1 2 3
## 4 5 6
C<- cbind(A, c(1,2,3), c(4,5,6));
print(C);
## A S D
## X 1 4 8 1 4
## Y 2 6 9 2 5
## Z 3 7 0 3 6
A[1,];
## A S D
## 1 4 8
A[,1];
## X Y Z
## 1 2 3
A[-3,]; # except row3
## A S D
## X 1 4 8
## Y 2 6 9
A[2,2];#second row second colum
## [1] 6
A[c(TRUE, FALSE, TRUE),]; #first row is true, second row is true, third row is true Only one and three row appears
## A S D
## X 1 4 8
## Z 3 7 0
A[2,2]<-100;
print(A)
## A S D
## X 1 4 8
## Y 2 100 9
## Z 3 7 0
A[A>4];
## [1] 100 7 8 9
B<-rbind(A, c(1,2,3),c(4,4,5));
print(B);
## A S D
## X 1 4 8
## Y 2 100 9
## Z 3 7 0
## 1 2 3
## 4 4 5
C<-cbind(A, c(1,2,3), c(4,5,6));
print(C);
## A S D
## X 1 4 8 1 4
## Y 2 100 9 2 5
## Z 3 7 0 3 6
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE
parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.