r

R: How to Draw heat map divided by a digonal line?

元气小坏坏 提交于 2021-02-10 23:43:37
问题 I came across this article on Nature Methods which provided a very nice heatmap: http://www.nature.com/nmeth/journal/v12/n4/full/nmeth.3311.html Different from other heat map is each rectangle is divided by a diagonal line, with 1 part represent the literature data and the other in-house data. I think this is a very nice way to compare the data. However, I do not know how to draw this pic in R. Does anyone have any clue on how to do this? A small screenshot is provided below: Below is a demo

Efficient Way to Convert Vector of Distances to Distance Object in R (ideally without creating a full distance matrix)

微笑、不失礼 提交于 2021-02-10 23:42:54
问题 I have a vector of distances which I get from some other procedure and want to convert it to a dist object in the R language . Below I give an example how such a vector looks like : distVector is computed in the same way said other procedure computes the distance vector. Ideally, I would like to transform this vector into a distance matrix ( dist object) without wasting resources. I think I could just transform it to a matrix by copying it as upper triangular and lower triangular matrix,

Efficient Way to Convert Vector of Distances to Distance Object in R (ideally without creating a full distance matrix)

青春壹個敷衍的年華 提交于 2021-02-10 23:39:52
问题 I have a vector of distances which I get from some other procedure and want to convert it to a dist object in the R language . Below I give an example how such a vector looks like : distVector is computed in the same way said other procedure computes the distance vector. Ideally, I would like to transform this vector into a distance matrix ( dist object) without wasting resources. I think I could just transform it to a matrix by copying it as upper triangular and lower triangular matrix,

Sum Values of Every Column in Data Frame with Conditional For Loop

喜你入骨 提交于 2021-02-10 23:27:32
问题 So I want to go through a data set and sum the values from each column based on the condition of my first column. The data and my code so far looks like this: x v1 v2 v3 1 0 1 5 2 4 2 10 3 5 3 15 4 1 4 20 for(i in colnames(data)){ if(data$x>2){ x1 <-sum(data[[i]]) } else{ x2 <-sum(data[[i]]) } } My assumption was that the for loop would call each column by name from the data and then sum the values in each column based on whether they matched the condition of column x. I want to sum half the

How to find all the possible permutations of a matrix in R?

喜欢而已 提交于 2021-02-10 23:20:01
问题 I have a matrix, for example, 5x5. [,1] [,2] [,3] [,4] [,5] [1,] 22 -2 -2 -2 2 [2,] -2 22 2 2 2 [3,] -2 2 22 2 2 [4,] -2 2 2 22 2 [5,] 2 2 2 2 22. As you can see, the matrix is symmetric. Above the main diagonal, there are 4+3+2+1=10 positions, and I find via combn all the possible (permutation) matrices, which have (-2) 3 times in these 10 positions. That means 10!/3!*7!=120 matrices. But some of them are equivalent. So,my problem is how to find the non-equivalent matrices from the 120. I am

How to find all the possible permutations of a matrix in R?

天大地大妈咪最大 提交于 2021-02-10 23:19:03
问题 I have a matrix, for example, 5x5. [,1] [,2] [,3] [,4] [,5] [1,] 22 -2 -2 -2 2 [2,] -2 22 2 2 2 [3,] -2 2 22 2 2 [4,] -2 2 2 22 2 [5,] 2 2 2 2 22. As you can see, the matrix is symmetric. Above the main diagonal, there are 4+3+2+1=10 positions, and I find via combn all the possible (permutation) matrices, which have (-2) 3 times in these 10 positions. That means 10!/3!*7!=120 matrices. But some of them are equivalent. So,my problem is how to find the non-equivalent matrices from the 120. I am

Condtionally create new columns based on specific numeric values (keys) from existing column

心不动则不痛 提交于 2021-02-10 22:47:26
问题 I have a data.frame df where the column x is populated with integers (1-9). I would like to update columns y and z based on the value of x as follows: if x is 1,2, or 3 | y = 1 ## if x is 1,4, or 7 | z = 1 if x is 4,5, or 6 | y = 2 ## if x is 2,5, or 8 | z = 2 if x is 7,8, or 9 | y = 3 ## if x is 3,6, or 9 | z = 3 Below is a data.frame with the desired output for y and z df <- structure(list(x = c(1L, 2L, 3L, 3L, 4L, 2L, 1L, 2L, 5L, 2L, 1L, 6L, 3L, 7L, 3L, 2L, 1L, 4L, 3L, 2L), y = c(1L, 1L,

How to replace multiple values in a string depending on a list of keys

五迷三道 提交于 2021-02-10 22:42:24
问题 I have this data which I want to replace each value with a fixed value from another list values key1 key3;key4;key1 key2;key1 Here is the list that "translates" each key into something else (these are just examples so it is not enought to just change the word "key" to "code". key code key1 code1 key2 code2 key3 code3 key4 code4 So the end product should look like this: values code1 code3;code4;code1 code2;code1 This is how I tried to solve it but got stuck: values = tibble(id = 1:3, values =

How to convert a multi variate time series object to a data frame?

烈酒焚心 提交于 2021-02-10 22:41:33
问题 I would like to do the reverse operation explained in this question: convert data frame with date column to time series. For example the decomposition of the co2 data is a multi variate time series: m <- decompose(co2) > str(m) List of 6 $ x : Time-Series [1:468] from 1959 to 1998: 315 316 316 318 318 ... $ seasonal: Time-Series [1:468] from 1959 to 1998: -0.0536 0.6106 1.3756 2.5168 3.0003 ... $ trend : Time-Series [1:468] from 1959 to 1998: NA NA NA NA NA ... $ random : Time-Series [1:468]

Using R with Jupyter notebook installation

╄→尐↘猪︶ㄣ 提交于 2021-02-10 22:40:12
问题 I have installed R from the official site and want to use it from jupyter notebook and jupyterlab. For that i have installed IRkernal in R using: install.packages('IRkernel') and then when I type IRkernel::installspec(user = FALSE) to make this installation visible globally, I get following error: Error in IRkernel::installspec(user = FALSE) : jupyter-client has to be installed but “jupyter kernelspec --version” exited with code 127. In addition: Warning message: In system2("jupyter", c(