如何引用包含加号的变量?

huangapple go评论108阅读模式
英文:

How to reference a variable containing plus sign?

问题

数据集blood_storage来自包medicaldata,包含一个名为BN+的变量。我如何在模型的公式中原样输入该变量?以下代码将导致错误:

lm(TimeToRecurrence ~ RBC.Age.Group + Median.RBC.Age + Age + AA + FamHx + PVol + TVol + T.Stage +
                bGS + BN+ + OrganConfined, data=blood_storage)

是否有解决办法,可以重命名变量以去除+符号?

英文:

The dataset blood_storage from the package medicaldata contains a variable BN+. How can I enter that variable as is in a model's formula? The following code will cause an error:

lm(TimeToRecurrence ~ RBC.Age.Group + Median.RBC.Age + Age + AA + FamHx + PVol + TVol + T.Stage +
                bGS + BN+ + OrganConfined, data=blood_storage)

Is there a workaround of the variable must be renamed to remove the + sign?

答案1

得分: 1

答案相同,对于具有空格的变量,请使用反引号。

lm(TimeToRecurrence ~ RBC.Age.Group + Median.RBC.Age + Age + AA + FamHx + PVol + TVol + T.Stage + bGS + `BN+` + OrganConfined, data=blood_storage)
英文:

The answer is the same for variables that have spaces in them. Use backticks.

lm(TimeToRecurrence ~ RBC.Age.Group + Median.RBC.Age + Age + AA + FamHx + PVol + TVol + T.Stage + bGS + `BN+` + OrganConfined, data=blood_storage)

huangapple
  • 本文由 发表于 2023年6月26日 12:23:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76553501.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定