错误:如果... heatmap.2,列索引必须最大为1. [英] Error: Column indexes must be at most 1 if... heatmap.2
问题描述
我在heatmap.2中收到一个错误,并且在这里发现了类似的错误 R:knnImputation给出了错误,但尚无答案.我不明白这个问题.我是这个世界的新手,如果有任何错误,请提前抱歉.
I received an error in heatmap.2, and I found similar error here R : knnImputation Giving Error but it doesn't have an answer yet. I couldn't understand the problem. I am new to this world, sorry in advance if there is any mistake.
我有一个数据帧df
,其中有144行,177列,其中显示了timeAverage
函数openair package
在2005-2016
之间的年月平均值.
I have a dataframe df
with 144 rows,177 columns which shows the monthly averages of years between 2005-2016
by timeAverage
function openair package
.
这是df
中的一个小例子:
date Year Month Adana-Catalan Adana-Dogankent Adana-Meteoroloji
2008/09/01 2008 9 NaN NaN NaN
2008/10/01 2008 10 NaN NaN 1.7948718
2008/11/01 2008 11 NaN NaN 2.0909091
2008/12/01 2008 12 1.2694064 12.2384106 0.7272727
2009/01/01 2009 1 2.3150358 12.7479339 10.3779762
2009/02/01 2009 2 2.8241107 18.4320175 2.4494949
2009/03/01 2009 3 2.0401606 8.4597523 1.6529412
2009/04/01 2009 4 1.8604651 4.8560000 1.1267606
2009/05/01 2009 5 2.1087719 1.8202247 NaN
2009/06/01 2009 6 4.0695103 2.1463415 1.1111111
2009/07/01 2009 7 5.4016393 8.1298905 NaN
2009/08/01 2009 8 0.1313869 16.9874411 NaN
2009/09/01 2009 9 NaN 5.3753943 NaN
2009/10/01 2009 10 1.6626506 8.8000000 1.8388889
2009/11/01 2009 11 1.4177632 NaN 3.9879154
2009/12/01 2009 12 0.9644128 NaN 5.0281457
2010/01/01 2010 1 0.2608696 4.0898876 3.1981424
2010/02/01 2010 2 0.7619048 NaN 4.3169811
删除非数字列:
df.monthly <- df[,-c(1:3)] #remove non-numeric columns
df.monthly.un <- unlist(df.monthly) #unlist the list
df.monthly.un[is.nan(df.monthly.un)] <- -999 #replace NaNs with -999
monthly.dim <- dim(df.monthly)
monthly.frame <- matrix(df.monthly.un, monthly.dim) #convert unlist to matrix
然后我计算距离矩阵并生成树状图.最后,我使用heatmap.2
生成带有树状图的热图.
then I calculated distance matrix and produced dendograms. Finally, I used heatmap.2
to produce heatmap with dendograms.
monthly.dist <- dist(monthly.frame)
monthly.hclust <- hclust(monthly.dist, method="complete")
monthly.dist2 <- dist(t(monthly.frame))
colClust <- as.dendrogram(hclust(monthly.dist2, method="complete"))
rowClust <- as.dendrogram(monthly.hclust)
colpalette <- colorRampPalette(c("red","blue","green"))(n=100)
heatmap.2(monthly.frame, scale="none",
col=colpalette, trace= "none", cexRow=0.6, cexCol=1,
cex.main=0.7, key=T, Rowv=rowClust, labRow=df[,1],
main=expression("2005-2016 SO"[2] * " (ug/m"^3*")"))
但是,当我运行代码时,它给出了错误:
However, when I run the code, it gives the error:
Error: Column indexes must be at most 1 if positive, not 22, 23, 24, 25, 21, 18, 19, 20, 16, 17, 12, 10, 11, 15, 13, 14, 3, 9, 8, 4, 7, 5, 6, 2, 124, 125, 121, 122, 123, 133, 132, 131, 134, 135, 126, 129, 127, 128, 130, 136, 137, 143, 144, 141, 142, 138, 139, 140, 57, 58, 55, 56, 42, 47, 41, 40, 36, 38, 37, 39, 46, 43, 44, 45, 34, 35, 26, 27, 28, 29, 30, 31, 32, 33, 59, 54, 53, 48, 49, 50, 51, 112, 116, 117, 114, 115, 88, 89, 52, 60, 63, 70, 75, 73, 74, 79, 77, 76, 78, 66, 67, 62, 65, 71, 64, 61, 72, 97, 87, 85, 86, 90, 98, 91, 83, 84, 92, 94, 96, 93, 95, 68, 69, 82, 80, 81, 113, 110, 111, 109, 118, 119, 120, 101, 105, 103, 104, 99, 106, 100, 102, 107, 108
知道为什么会发生此错误吗?预先感谢!
Any idea why this error occurs? Thanks in advance!
推荐答案
我今天遇到了问题,发现应该将tbl
对象转换为data.frame
对象!!这是令人讨厌的一点,即不同的软件包没有兼容性.
I came into the problem today,and I found that we should transform our tbl
object into data.frame
object!!This is one disgusting point that different packages do not have compatibility.
#check your df class,I think your df is actually a tbl object
class(df)
df_new <- as.data.frame(df)
这篇关于错误:如果... heatmap.2,列索引必须最大为1.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!