简体   繁体   English

如何在R中创建具有两个因子和一个数值数据类型的热图?

[英]How to Create a Heat map with two factors and one numeric data type in R?..

Consider the following scenario :- 考虑以下情形:

       Col1 Col2 Col3

Col1 & Col2 are belongs to character data type. Col1和Col2属于字符数据类型。 Col3 is the numeric data type. Col3是数字数据类型。

Each value in Col3 denotes the combinational behavior of Col1 & Col2. Col3中的每个值表示Col1和Col2的组合行为。

So, I want to create a data matrix of size (Col1 * Col2) and stores the col3 value accordingly. 因此,我想创建一个大小为(Col1 * Col2)的数据矩阵,并相应地存储col3值。

I would be really happy, If someone could help me on this..... 如果有人可以帮助我,我将非常高兴.....

You can use functions from data.table package 您可以使用data.table包中的函数

data <- data.table(a = c('a', 'b', 'c', 'a'), b = c('d', 'e', 'f', 'e'), c = c(3,5,6,7))
casted <- dcast(data, a~b, value.var = 'c')

If you need matrix as a result, you have to do additional conversion: 如果结果需要矩阵,则必须执行其他转换:

matr <- as.matrix(casted[, 2:ncol(casted), with = F])
rownames(matr) <- casted[[1]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM