如何使用 r 中的 shapiro.test 计算具有 NA 值的数据框中每一列的 p.value?

How to calculate p.value of each column in a data frame with NA values using shapiro.test in r?

这是我目前尝试过的方法。它有效,但它只告诉我没有 NA 的数据的 p.value。我的大部分数据在少数地方有 NA 值,最多占数据的 1/3。

normal <- apply(cor_phys, 2, function(x) shapiro.test(x)$p.value)

我想尝试将 na.rm 添加到函数中,但它不起作用。帮忙?

#calculate the correlations between all variables
corres <- cor_phys %>%                  #cor_phys is my data
  as.matrix %>%
  cor(use="complete.obs") %>%           #complete.obs does not use NA
  as.data.frame %>%
  rownames_to_column(var = 'var1') %>%
  gather(var2, value, -var1)

#removes duplicates correlations
corres <- corres %>%
  mutate(var_order = paste(var1, var2) %>%
         strsplit(split = ' ') %>%
         map_chr( ~ sort(.x) %>% 
         paste(collapse = ' '))) %>%
  mutate(cnt = 1) %>%
  group_by(var_order) %>%
  mutate(cumsum = cumsum(cnt)) %>%
  filter(cumsum != 2) %>%
  ungroup %>%
  select(-var_order, -cnt, -cumsum)        #removes unneeded columns

这不是我自己写的,但这是我根据需要使用和工作的答案。我使用的页面 link 是: How to compute correlations between all columns in R and detect highly correlated variables