r

Find the largest values on a matrix in R

社会主义新天地 提交于 2021-02-10 03:11:46
问题 I am working on a matrix in R, 230 x 230 and I want to extract the 10 (or any other number than 1) max inputs on the matrix, both their position and value. The extra problem is that this is a similarity matrix, so I have 1s in the diagonal which of course I want to leave out of the max search. Any ideas or commands for that? 回答1: A neat way to do this in general is with the underused arrayInd function, which gives you row and column positions for plain jane vector positions. That's how which(

Find the largest values on a matrix in R

泄露秘密 提交于 2021-02-10 03:07:23
问题 I am working on a matrix in R, 230 x 230 and I want to extract the 10 (or any other number than 1) max inputs on the matrix, both their position and value. The extra problem is that this is a similarity matrix, so I have 1s in the diagonal which of course I want to leave out of the max search. Any ideas or commands for that? 回答1: A neat way to do this in general is with the underused arrayInd function, which gives you row and column positions for plain jane vector positions. That's how which(

Find the largest values on a matrix in R

有些话、适合烂在心里 提交于 2021-02-10 03:06:44
问题 I am working on a matrix in R, 230 x 230 and I want to extract the 10 (or any other number than 1) max inputs on the matrix, both their position and value. The extra problem is that this is a similarity matrix, so I have 1s in the diagonal which of course I want to leave out of the max search. Any ideas or commands for that? 回答1: A neat way to do this in general is with the underused arrayInd function, which gives you row and column positions for plain jane vector positions. That's how which(

.SD and .SDcols for the i expression in data.table join

≯℡__Kan透↙ 提交于 2021-02-10 02:57:09
问题 i'm trying to copy a subset of columns from Y to X based on a join, where the subset of columns is dynamic I can identify the columns quite easily: names(Y)[grep("xxx", names(Y))] but when i try to use that code in the j expression, it just gives me the column names, not the values of the columns. the .SD and .SDcols gets pretty close, but they only apply to the x expression . I'm trying to do something like this: X[Y[names(Y)[grep("xxx", names(Y))] := .SD, .SDcols = names(Y)[grep("xxx",

.SD and .SDcols for the i expression in data.table join

别说谁变了你拦得住时间么 提交于 2021-02-10 02:56:06
问题 i'm trying to copy a subset of columns from Y to X based on a join, where the subset of columns is dynamic I can identify the columns quite easily: names(Y)[grep("xxx", names(Y))] but when i try to use that code in the j expression, it just gives me the column names, not the values of the columns. the .SD and .SDcols gets pretty close, but they only apply to the x expression . I'm trying to do something like this: X[Y[names(Y)[grep("xxx", names(Y))] := .SD, .SDcols = names(Y)[grep("xxx",

.SD and .SDcols for the i expression in data.table join

一笑奈何 提交于 2021-02-10 02:55:57
问题 i'm trying to copy a subset of columns from Y to X based on a join, where the subset of columns is dynamic I can identify the columns quite easily: names(Y)[grep("xxx", names(Y))] but when i try to use that code in the j expression, it just gives me the column names, not the values of the columns. the .SD and .SDcols gets pretty close, but they only apply to the x expression . I'm trying to do something like this: X[Y[names(Y)[grep("xxx", names(Y))] := .SD, .SDcols = names(Y)[grep("xxx",

How to use {gtsummary} package in r shiny app

纵然是瞬间 提交于 2021-02-10 02:29:51
问题 Is it possible to render a table with {gtsummary} in a shiny app? library(gtsummary) # make dataset with a few variables to summarize iris2 <- iris %>% select(Sepal.Length, Sepal.Width, Species) # summarize the data with our package table1 <- tbl_summary(iris2) table1 in a Shiny app: -> shinyApp( ui = fluidPage( fluidRow( column(12, tableOutput('table') ) ) ), server = function(input, output) { output$table <- renderTable(table1) }) Thank you. 回答1: Maybe this what you are looking for. To

Combine and merge legends in ggplot2 with patchwork

和自甴很熟 提交于 2021-02-09 19:34:25
问题 I would like to combine two or more plots merging their legends. For example, I can create some data and two scenarios as follows. # packages library(ggplot2) library(patchwork) # first plot set.seed(07042020) x <- runif(50) y <- runif(50) data1 <- data.frame(x = x, y = y, z = runif(50, 0, 2)) p1 <- ggplot(data1) + geom_point(aes(x, y, col = z)) p1 data2 <- data.frame(x = x, y = y, z = runif(50, -1, 1)) p2 <- ggplot(data2) + geom_point(aes(x, y, col = z)) p2 The following code is what I tried

Combine and merge legends in ggplot2 with patchwork

牧云@^-^@ 提交于 2021-02-09 19:31:39
问题 I would like to combine two or more plots merging their legends. For example, I can create some data and two scenarios as follows. # packages library(ggplot2) library(patchwork) # first plot set.seed(07042020) x <- runif(50) y <- runif(50) data1 <- data.frame(x = x, y = y, z = runif(50, 0, 2)) p1 <- ggplot(data1) + geom_point(aes(x, y, col = z)) p1 data2 <- data.frame(x = x, y = y, z = runif(50, -1, 1)) p2 <- ggplot(data2) + geom_point(aes(x, y, col = z)) p2 The following code is what I tried

Combine and merge legends in ggplot2 with patchwork

谁说胖子不能爱 提交于 2021-02-09 19:30:00
问题 I would like to combine two or more plots merging their legends. For example, I can create some data and two scenarios as follows. # packages library(ggplot2) library(patchwork) # first plot set.seed(07042020) x <- runif(50) y <- runif(50) data1 <- data.frame(x = x, y = y, z = runif(50, 0, 2)) p1 <- ggplot(data1) + geom_point(aes(x, y, col = z)) p1 data2 <- data.frame(x = x, y = y, z = runif(50, -1, 1)) p2 <- ggplot(data2) + geom_point(aes(x, y, col = z)) p2 The following code is what I tried