如何从R中的包中提取公式或特定函数?
我使用R软件包“pt”来计算累积前景理论值 第一个输入如下:如何从R中的包中提取公式或特定函数?,r,package,R,Package,我使用R软件包“pt”来计算累积前景理论值 第一个输入如下: choice_ids <- c(1, 1, 1, 1, 2, 2, 2, 2) gamble_ids <- c(1, 1, 1, 2, 1, 1, 2, 2) outcome_ids <- c(1, 2, 3, 1, 1, 2, 1, 2) objective_consequences <- c(2500, 2400, 0, 2400,2500, 0, 2400, 0) probability_strings
choice_ids <- c(1, 1, 1, 1, 2, 2, 2, 2)
gamble_ids <- c(1, 1, 1, 2, 1, 1, 2, 2)
outcome_ids <- c(1, 2, 3, 1, 1, 2, 1, 2)
objective_consequences <- c(2500, 2400, 0, 2400,2500, 0, 2400, 0)
probability_strings <- c("0.33", "0.66", "0.01", "1.0","0.33", "0.67", "0.34", "0.66")
my_choices <- Choices(choice_ids=choice_ids,gamble_ids=gamble_ids,outcome_ids=outcome_ids,objective_consequences=objective_consequences,probability_strings=probability_strings)
choice\u id出现pt
从CRAN上取下,但可以从github存档中安装:
library(devtools)
install_github("cran/pt")
comparePT()
是一个函数。检查这些与常规S3有点不同。首先使用showMethods()
查看可用的方法,然后对感兴趣的方法使用getMethod()
showMethods("comparePT")
# Function: comparePT (package pt)
# object="Choices"
getMethod("comparePT", "Choices")
# Method Definition:
#
# function ...
但是,comparePT()
的输出只是一个常规的data.frame,因此您可以像往常一样使用$
对其进行子集化。并将包装为.numeric()
作为其编码为字符
as.numeric(comparePT(my_choices, linear_in_log_odds_prob_weight,
linear_in_log_odds_prob_weight, tk_1992_utility, 4)$pt)
# [1] 881.3 943.2 312.6 307.2
如果comparePT
返回一个数据帧,您可以像处理任何其他数据帧一样将该列提取为向量
as.numeric(comparePT(my_choices, linear_in_log_odds_prob_weight,
linear_in_log_odds_prob_weight, tk_1992_utility, 4)$pt)
# [1] 881.3 943.2 312.6 307.2