获取R公式的右侧变量 [英] Get the right hand side variables of an R formula
本文介绍了获取R公式的右侧变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在写我的第一个S3类和相关的方法,我想知道如何子集我的输入数据集,以便只保留公式中指定的变量
I'm writing my first S3 class and associated methods and I would like to know how to subset my input data set in order to keep only the variables specified in the formula?
data(iris)
f <- Species~Petal.Length + Petal.Width
使用 model.frame(f,iris)
我得到一个包含公式中所有变量的子集。如何自动仅保留右侧变量(在示例中 Petal.Length
和 Petal.Width
)?
With model.frame(f,iris)
I get a subset with all the variables in the formula. How to automatically keep only the right hand side variables (in the example Petal.Length
and Petal.Width
)?
推荐答案
您想要标签
和 code>;请参阅
?标签
,?terms
,?terms.object
labels(terms(f))
# [1] "Petal.Length" "Petal.Width"
特别是 labels.terms
术语
对象的term.labels
属性,不包括LHS变量。
In particular, labels.terms
returns the "term.labels"
attribute of a terms
object, which excludes the LHS variable.
这篇关于获取R公式的右侧变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文