R: `ID : Coercing LHS to a list` 在添加 ID 列中,为什么?

标签 r runtime-error warnings

我有数据

       N11.1 N22.2 N33.1 N44.1 N21.1 N31.1 N32.1
Sinus      1     0     0   0.0     0     0  12.0
ArrAHB     1     0     0   0.1     0     0  20.9

我想在其中添加一个额外的列 IDSinusArrAHB .
require(lattice)
Sinus<-c(1,0,0,0,0,0,12)
ArrAHB<-c(1,0,0,0.1,0,0,20.9)
Labels<-c("N11.1","N22.2","N33.1","N44.1","N21.1","N31.1","N32.1")
ID<-c("Sinus","Arr/AHB")
data.female<-data.frame(Sinus,ArrAHB,row.names=Labels)
data.female<-t(data.female)

> data.female$ID<-ID

Warning message:
In data.female$ID <- ID : Coercing LHS to a list

Why does the creation of the ID column cause the coercion in the data.frame?



附言我的目标是将这些数据转换为类似 here 的形式为 barchart(N11.1+N22.1+N33.1+N44.1+N21.1+N31.1+N32.1 ~ ID, data=data.female)这需要一个新的 ID 列 here ,我不明白为什么这个 ID 添加有时有效,有时无效。请解释。

最佳答案

它发出警告,作为转置的结果 t()是一个矩阵。矩阵没有可访问的列名。在进行 ID 分配之前,您必须使用 as.data.frame() 将矩阵强制转换为数据框。

这有效。

Sinus<-c(1,0,0,0,0,0,12)
ArrAHB<-c(1,0,0,0.1,0,0,20.9)
Labels<-c("N11.1","N22.2","N33.1","N44.1","N21.1","N31.1","N32.1")
ID<-c("Sinus","Arr/AHB")
data.female<-data.frame(Sinus,ArrAHB,row.names=Labels)
data.female<-as.data.frame(t(data.female))

data.female$ID<-ID

请记住,数据框是按列而不是按行定义的。数据框定义应按列进行。

关于R: `ID : Coercing LHS to a list` 在添加 ID 列中,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40681628/

相关文章:

c++ - 无法使用 VideoWriter 从网络摄像头捕获中写入

MySQL客户端分段故障

android - 在 Android 上构建 Xamarin.Forms 应用程序时识别大量 XA0106 警告的罪魁祸首

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

r - 按 ExpressionSet 对象的样本进行子集化

来自 Git 存储库的 R studio 项目,自签名证书问题

css - 在 R 演示文稿中扩展 R 代码块的宽度

用平滑样条替换所有 NA

c++ - 无法运行 Opengl 程序

git - 执行 git push 时出现 "diff.renamelimit variable"警告