![]() + YakData SmartDesktop with RStudio Desktop Server Open Source is the smart way to develop R programs, Shiny web apps & RMarkdown docs on your desktop. Get started on GitHub at Stephen-McDaniel/SmartDesktop-RStudio. And since Docker is so incredibly ubiquitous, you know Windows, Mac, and Linux users will all be happy! All wrapped neatly into Docker via docker-compose. Includes R 4.1.3, the RStudio Desktop IDE, the tidyverse, verse, and geospatial-related tools from the R rocker-org project as a web app. The intelligent, portable, reproducible way to develop R programs, Shiny web apps & RMarkdown docs on your desktop. ![]() We may want to convert a vector to a matrix - using the as.matrix() function for exclusive coercion mn <- 1:6Īs.matrix(mn) # as.You know that R 4.1.3 is out but don’t want to disrupt your current setup? Want to have multiple R versions with compartmentalized projects and libraries on your computer? Teaching people how to use R and need the entire class to all be on the same, easy-to-install system complete with R 4.1.3, RStudio Desktop, shiny dev environment, the tidyverse, geospatial tools, tex & publishing-related packages included? YakData SmartDesktop with RStudio Server Open Source Sum(mat10) # sum of all the elements in the matrixĮigen(mat10) # to calculate the eigen values RowMeans(mat10) # return the means of the columns Mat10 %*% mat11 # Multiplication of matrix (the actual matrix multiplication)ĬolMeans(mat10) # return the means of the columns Mat10 * mat11 # Multiplication of 2 matrices (element wise multiplication) Mat10 * 2 # Matrix multiplication (scalar multiplied to a matrix) Mat10 - mat11 # Substraction of 2 matrices Mat10 + 10 # Addition of scalar to a matrix Mathematical operations on matrix # create 2 matrices # vector should be the multiple of shorter length vector # both the vectors should be of either the same length or length of bigger Using cbind() and rbind() functions in the matrix: m6 <- 0:3 M3 # extracting column elements of a specific row, in this case row 3ĭiag(m3) # extracts the diagonal elements of the matrixĪssign row names and column names to the matrix m4 <- matrix(1:4, byrow = T, ncol = 2)ĭimnames(m4) <- list(c("COL1", "COL2"), c("ROW1", "ROW2")) M3 # extracting column elements of a specific row, in this case row 2 M3 # extracting column elements of a specific row, in this case row 1 ![]() M3 # extracting row elements of a specific column, in this case column 3 M3 # extracting row elements of a specific column, in this case column 2 M3 # extracting row elements of a specific column, in this case column 1 M3 # extracting an element by giving its location Now, let us do some subsetting in matrix m3 <- matrix(1:9, nrow = 3, ncol = 3) # byrow = T would tell R to fill the elements row wise Matrix(c(1, 2, 3, 4), c(2, 2)) # elements and dimensions of the matrix both defined using a c()function M2 <- matrix(seq(1, 4, 1), nrow = 2, ncol = 2, byrow = T) # byrow = T would tell R to fill the elements row wise To fill row wise, we need to tell R exclusively. ![]() M2 # note that by default the matrix is filled column wise. M2 <- matrix(seq(1, 4, 1), nrow = 2, ncol = 2) # used a seq() to get a sequence of elements M2 <- matrix(nrow = 2, ncol = 2) # we will get the matrix filled with NA as we have not defined the matrix values Ncol(m1) # outputs the number of columns in the matrix Nrow(m1) # outputs the number of rows in the matrix In this case elements stored in the matrix are integer type M1 <- 1:4 # m1 is a vector object with a sequence of elementsĭim(m1) <- c(2, 2) # define the dimension as 2X2 (2 rows and 2 columns) to make it a matrixĬlass(m1) # show the class type, in this case it would be matrix class We cannot have elements of mixed modes/class types such as both integer and character elements in the same matrix. We can have character, integer or complex elements in the matrices and so on. Matrix is a data type in R with the dimension attribute - the rows & the columns. Programming in R - tutorial : Matrix Data Type Programming in R - tutorial : Matrix Data Type ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |