matrix

Rank of a matrix in R

余生颓废 提交于 2021-01-16 08:46:52
问题 I want to test the rank of a matrix, is there someone who can recommend a package/function in R for this? 回答1: You can try the function qr ("qr", because it performs a QR decomposition): #define a matrix for this example M <- matrix(data = rnorm(12), ncol = 3) #run the function qr() qr(M)$rank #Alternative: load the Matrix package... require(Matrix) #...and run the function rankMatrix() rankMatrix(M)[1] 回答2: http://cran.r-project.org/web/packages/Matrix/Matrix.pdf, page 101 http://cran.r

Rotate a 2d matrix to the right [duplicate]

戏子无情 提交于 2021-01-15 18:33:13
问题 This question already has answers here : Rotating a NxN matrix in Java (11 answers) Closed 19 hours ago . I want a 2d matrix to rotate to the right, it compiles fine but when I try to the run it says that the array index is out of bounds exception . For example, I want {{10,20,30},{40,50,60}} to rotate into {{40,10},{50,20},{60,30}} : public static int[][] rotate(int[][] m) { int[][] rotateM = new int[m[0].length][m.length]; for (int i = 0; i < m.length; i++) { for (int j = 0; j < m[0].length

Rotate a 2d matrix to the right [duplicate]

拟墨画扇 提交于 2021-01-15 18:31:46
问题 This question already has answers here : Rotating a NxN matrix in Java (11 answers) Closed 19 hours ago . I want a 2d matrix to rotate to the right, it compiles fine but when I try to the run it says that the array index is out of bounds exception . For example, I want {{10,20,30},{40,50,60}} to rotate into {{40,10},{50,20},{60,30}} : public static int[][] rotate(int[][] m) { int[][] rotateM = new int[m[0].length][m.length]; for (int i = 0; i < m.length; i++) { for (int j = 0; j < m[0].length

Rotate a 2d matrix to the right [duplicate]

牧云@^-^@ 提交于 2021-01-15 18:29:51
问题 This question already has answers here : Rotating a NxN matrix in Java (11 answers) Closed 19 hours ago . I want a 2d matrix to rotate to the right, it compiles fine but when I try to the run it says that the array index is out of bounds exception . For example, I want {{10,20,30},{40,50,60}} to rotate into {{40,10},{50,20},{60,30}} : public static int[][] rotate(int[][] m) { int[][] rotateM = new int[m[0].length][m.length]; for (int i = 0; i < m.length; i++) { for (int j = 0; j < m[0].length

How to use R base plot to create a stacked histogram as barcode plot with row-wise color pattern from a R base table

孤者浪人 提交于 2021-01-07 03:57:17
问题 I came across a neat feature when plotting a table with base::plot() > test.matrix<-matrix(c(70,120,65,140,13,68,46,294,52,410),ncol=2,byrow=TRUE) > rownames(test.matrix)<-c("BC.1","BC.2","GC","MO","EB") > colnames(test.matrix)<-c("12m","3m") > test.matrix <- as.table(test.matrix) > test.matrix 12m 3m BC.1 70 120 BC.2 65 140 GC 13 68 MO 46 294 EB 52 410 > plot(test.matrix) This plots sth like a barcode plot, with bar height reflecting row-wise difference and bar width reflecting table cell

How to use R base plot to create a stacked histogram as barcode plot with row-wise color pattern from a R base table

给你一囗甜甜゛ 提交于 2021-01-07 03:54:30
问题 I came across a neat feature when plotting a table with base::plot() > test.matrix<-matrix(c(70,120,65,140,13,68,46,294,52,410),ncol=2,byrow=TRUE) > rownames(test.matrix)<-c("BC.1","BC.2","GC","MO","EB") > colnames(test.matrix)<-c("12m","3m") > test.matrix <- as.table(test.matrix) > test.matrix 12m 3m BC.1 70 120 BC.2 65 140 GC 13 68 MO 46 294 EB 52 410 > plot(test.matrix) This plots sth like a barcode plot, with bar height reflecting row-wise difference and bar width reflecting table cell

Faster alternative to R car::Anova for sum of square crossproduct matrix calculation for subsets of predictors

穿精又带淫゛_ 提交于 2021-01-07 01:43:30
问题 I need to compute the sum of squares crossproduct matrix (indeed the trace of this matrix) in a multivariate linear model, with Y (n x q) and X (n x p). Standard R code for doing that is: require(MASS) require(car) # Example data q <- 10 n <- 1000 p <- 10 Y <- mvrnorm(n, mu = rep(0, q), Sigma = diag(q)) X <- as.data.frame(mvrnorm(n, mu = rnorm(p), Sigma = diag(p))) # Fit lm fit <- lm( Y ~ ., data = X ) # Type I sums of squares summary(manova(fit))$SS # Type III sums of squares type = 3 #

Faster alternative to R car::Anova for sum of square crossproduct matrix calculation for subsets of predictors

左心房为你撑大大i 提交于 2021-01-07 01:40:21
问题 I need to compute the sum of squares crossproduct matrix (indeed the trace of this matrix) in a multivariate linear model, with Y (n x q) and X (n x p). Standard R code for doing that is: require(MASS) require(car) # Example data q <- 10 n <- 1000 p <- 10 Y <- mvrnorm(n, mu = rep(0, q), Sigma = diag(q)) X <- as.data.frame(mvrnorm(n, mu = rnorm(p), Sigma = diag(p))) # Fit lm fit <- lm( Y ~ ., data = X ) # Type I sums of squares summary(manova(fit))$SS # Type III sums of squares type = 3 #

Power BI Matrix - remove repeating column of a group

不羁的心 提交于 2021-01-07 01:35:10
问题 I have a Power BI Matrix below. It has 2 measures - Main Measure (a simple sum) and a Variance Measure. It has a column group called Category, which has 2 values - Category A and Category B. The Variance Measure is the subtraction of the Main Measure values between Category A and Category B, for corresponding time periods. For example, Main Measure value of 2020 Q1 for Category B is subtracted from the Main Measure value of 2020 Q1 for Category A . The result is the Variance Measure for 2020

Power BI Matrix - remove repeating column of a group

五迷三道 提交于 2021-01-07 01:34:22
问题 I have a Power BI Matrix below. It has 2 measures - Main Measure (a simple sum) and a Variance Measure. It has a column group called Category, which has 2 values - Category A and Category B. The Variance Measure is the subtraction of the Main Measure values between Category A and Category B, for corresponding time periods. For example, Main Measure value of 2020 Q1 for Category B is subtracted from the Main Measure value of 2020 Q1 for Category A . The result is the Variance Measure for 2020