Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205372

Tidyverse Select function does not keep the unnamed columns of an unclass item

$
0
0

How can I filter EFA factors to include items that have only the items having loadings greater than a certain threshold?

I used fa function. Here is a reproducible code:

bfi_cor <- cor(bfi_data)
bfi_data=bfi_data[complete.cases(bfi_data),]
factors_data <- fa(r = bfi_cor, nfactors = 4)

I unclassed the factor loadings as such:

df_EFA <- data.frame(unclass(factors_data$loadings))

Here is the head of the output:

           MR1          MR2          MR3           MR4
A1 -0.23768598  0.068096644  0.032857014  0.0007631509
A2  0.55855557  0.096152392  0.090485457 -0.0438972912
A3  0.65067617  0.068763169  0.040190930 -0.0215080952
A4  0.44606746 -0.007382889  0.181278979 -0.1956348388

I would like to create a data frame for, say MR2, to include only items that have loadings greater than or equal to 0.4

MR2_cutoff=df_EFA%>%filter(MR2>=0.4)%>%select(MR2)

So far so good but when I run this, I lose the column with the corresponding items listed on the first column.

MR2
<dbl>
0.7455404               
0.7393464               
0.7572845               
0.5704315               
0.5713734

But, I want to keep the item names such as A1, A2, A3, A4. Is it a feature in the 'filter' or 'select' function that I need to make sure to keep those corresponding item names? Thanks for your help in advance.


Viewing all articles
Browse latest Browse all 205372

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>