gpt4 book ai didi

r - 如何找出公式中的术语类别

转载 作者:行者123 更新时间:2023-12-04 05:59:07 25 4
gpt4 key购买 nike

给定一个公式对象,我可以通过以下方式找出术语的

> lapply(model.frame(~Type*Plant+uptake,data=CO2),class)
$Type
[1] "factor"

$Plant
[1] "ordered" "factor"

$uptake
[1] "numeric"

但这需要调用 model.frame,我想知道是否有更有效的方法。

最佳答案

您可以使用 all.vars 函数从公式对象中提取变量名称。

form <- ~Type*Plant+uptake
all.vars(form)
# [1] "Type" "Plant" "uptake"

找到变量的类别:

lapply(CO2[all.vars(form)], class)
# $Type
# [1] "factor"
#
# $Plant
# [1] "ordered" "factor"
#
# $uptake
# [1] "numeric"

关于r - 如何找出公式中的术语类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28040300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com