R 中 log2 的矩阵 as.numeric 的子集
我有一个 54675 个 obs 的数据矩阵 (data
)。 170 个变量。我想执行的
data.matrix.2 <- log2(data[,9:ncol(data)])
是第 9 列及以后的值。前面的 8 列是字符。我收到以下错误
Error in Math.data.frame(data.matrix[, 9:ncol(data)]) :
non-numeric variable in data frame:
是否有一种方法可以将矩阵的子集视为对数变换的数字。
谢谢
I have a data matrix (data
) of 54675 obs. of 170 variables. And I want to perform
data.matrix.2 <- log2(data[,9:ncol(data)])
i.e. for values from the 9th column and beyond. The 8 columns before that are characters. I get the following error
Error in Math.data.frame(data.matrix[, 9:ncol(data)]) :
non-numeric variable in data frame:
Is there a way to treat a subset of the matrix as.numeric for the the log transform.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的第一个想法是你已经得到了一个字符矩阵并且需要:
...但是 data.matrix() 应该强制为“数字”模式。哦,不,你去吧。您没有使用 data.matrix 函数......所以最好不要使用名称“data.matrix”,因为这也是 R 函数的名称。
您正确使用“[,]”,因此您对数据对象的假设可能有缺陷。其余 162 列中必须有一列作为因子或字符创建的数据。您需要运行 str(data.matrix) 来查看它/它们是哪一个。
My first thought was that you had gotten a character matrix and needed:
... but data.matrix() should coerce to 'numeric' mode. Oh, no, there you go. You weren't using the data.matrix function .... so it would be better not to use the name "data.matrix" since that is also the name of an R function.
You are properly using "[,]" so your assumptions about your data object are probably flawed. There must be a column of data that got created as factor or character in the remaining 162 columns. You need to run str(data.matrix) to see which one(s) it/they are.