[英]How can I reshape a data.table or data.farme in R without adding up the frequencies?
[英]Correlation of all variables in a data.farme in R
我知道向cor
输入 data.frame 会自动给出一个相关矩阵(例如cor(mtcars)
)。
但是我想知道为什么当我将自己的 data.frame ( dat_w
) 输入到cor
时,会出现以下错误?
我有NA
和Inf
但使用过use = 'pairwise.complete.obs'
。
dat_w <- read.csv('https://raw.githubusercontent.com/izeh/n/master/w1.csv', stringsAsFactors = F)
cor(dat_w, use = 'pairwise.complete.obs')
# >Error : 'x' must be numeric
因为您的第二列( gender
)不是数字。 尝试:
cor(dat_w[-2], use = 'pairwise.complete.obs')
我们可以自动找到数字的列
i1 <- sapply(dat_w, is.numeric)
out <- cor(dat_w[i1], use = 'pairwise.complete.obs')
如果我们想用某个值替换NaN
,即 0
out1 <- replace(out, is.nan(out)|is.na(out), 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.