在 papaja::apa_table 中将值削减到阈值以下的选项

Option to cut values below a threshold in papaja::apa_table

我不知道如何有选择地打印 table 高于或低于某个值的值。我正在寻找的是 Revelle 的 psych 包中的 "cut"。 MWE 下面。

library("psych")
library("psychTools")
derp <- fa(ability, nfactors=3)
print(derp, cut=0.5) #removes all loadings smaller than 0.5
derp <- print(derp, cut=0.5) #apa_table still doesn't print like this

问题是,如何将剪辑添加到 apa_table?打印 apa_table(derp) 打印整个 table,包括所有值。

来自 psychprint 方法不 return 格式化载荷,但仅考虑 table 方差。但是,您可以通过手动格式化加载 table:

来获得您想要的结果
library("psych")
library("psychTools")
derp <- fa(ability, nfactors=3)

# Class `loadings` cannot be coerced to data.frame or matrix
class(derp$Structure)
  [1] "loadings"
# Class `matrix` is supported by apa_table()
derp_loadings <- unclass(derp$Structure)
class(derp_loadings)
  [1] "matrix"
# Remove values below "cut"
derp_loadings[derp_loadings < 0.5] <- NA

colnames(derp_loadings) <- paste("Factor", 1:3)

apa_table(
  derp_loadings
  , caption = "Factor loadings"
  , added_stub_head = "Item"
  , format = "pandoc" # Omit this in your R Markdown document
  , format.args = list(na_string = "") # Don't print NA
)
*Factor loadings*
Item        Factor 1   Factor 2   Factor 3 
----------  ---------  ---------  ---------
reason.4                          0.60     
reason.16                                  
reason.17                         0.65     
reason.19                                  
letter.7               0.61                
letter.33              0.56                
letter.34              0.65                
letter.58                                  
matrix.45                                  
matrix.46                                  
matrix.47                                  
matrix.55                                  
rotate.3    0.70                           
rotate.4    0.73                           
rotate.6    0.63                           
rotate.8    0.63