[英]Is there an easier way to find correlations between categorical data and multiple column of numerical data in R?
I am looking for correlations between categorical data and numerical scores from a survey in RStudio.我正在从 RStudio 的一项调查中寻找分类数据和数字分数之间的相关性。 I am still learning R and was able to figure out a way to assign numbers to categories from my survey and compare them to a single column of data at a time.我仍在学习 R,并且能够找到一种方法来为我的调查中的类别分配数字,并将它们一次与单列数据进行比较。 However, this has proven rather tedious.然而,事实证明这相当乏味。 Is there a simpler way to create a table that compares the original categorical data now in Column1 to several columns of data in an excel file instead?有没有更简单的方法来创建一个表格,将 Column1 中的原始分类数据现在与 Excel 文件中的几列数据进行比较?
df <- read.table(text=" x
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Early career; with basic skills development; work contributes to the success of team goals'
'Entry-level; learning technical and professional skills'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Expert; has broad influence and experience within organization'
'Advanced; very senior; can solve most problems of issues that arise'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Expert; has broad influence and experience within organization'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Advanced; very senior; can solve most problems of issues that arise'
'Entry-level; learning technical and professional skills'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Advanced; very senior; can solve most problems of issues that arise'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Advanced; very senior; can solve most problems of issues that arise'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Entry-level; learning technical and professional skills'
'Entry-level; learning technical and professional skills'
'Early career; with basic skills development; work contributes to the success of team goals'
'Expert; has broad influence and experience within organization'
'Early career; with basic skills development; work contributes to the success of team goals'
'Advanced; very senior; can solve most problems of issues that arise'
'Entry-level; learning technical and professional skills'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Expert; has broad influence and experience within organization'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Advanced; very senior; can solve most problems of issues that arise'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Advanced; very senior; can solve most problems of issues that arise'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Entry-level; learning technical and professional skills'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Advanced; very senior; can solve most problems of issues that arise'
'Entry-level; learning technical and professional skills'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Advanced; very senior; can solve most problems of issues that arise'
'Advanced; very senior; can solve most problems of issues that arise'
'Advanced; very senior; can solve most problems of issues that arise'
'Advanced; very senior; can solve most problems of issues that arise'
'Entry-level; learning technical and professional skills'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Entry-level; learning technical and professional skills'
'Entry-level; learning technical and professional skills'
'Advanced; very senior; can solve most problems of issues that arise'
'Early career; with basic skills development; work contributes to the success of team goals'
'Advanced; very senior; can solve most problems of issues that arise'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Advanced; very senior; can solve most problems of issues that arise'
'Advanced; very senior; can solve most problems of issues that arise'
'Advanced; very senior; can solve most problems of issues that arise'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Expert; has broad influence and experience within organization'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Early career; with basic skills development; work contributes to the success of team goals'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Advanced; very senior; can solve most problems of issues that arise'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Entry-level; learning technical and professional skills'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Early career; with basic skills development; work contributes to the success of team goals'
'Advanced; very senior; can solve most problems of issues that arise'
'Advanced; very senior; can solve most problems of issues that arise'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Entry-level; learning technical and professional skills'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Entry-level; learning technical and professional skills'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Advanced; very senior; can solve most problems of issues that arise'
'Early career; with basic skills development; work contributes to the success of team goals'
'Advanced; very senior; can solve most problems of issues that arise'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Early career; with basic skills development; work contributes to the success of team goals'
'Advanced; very senior; can solve most problems of issues that arise'
'Advanced; very senior; can solve most problems of issues that arise'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Entry-level; learning technical and professional skills'
'Advanced; very senior; can solve most problems of issues that arise'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Advanced; very senior; can solve most problems of issues that arise'
'Early career; with basic skills development; work contributes to the success of team goals'
'Early career; with basic skills development; work contributes to the success of team goals'
'Entry-level; learning technical and professional skills'
'Advanced; very senior; can solve most problems of issues that arise'
'Advanced; very senior; can solve most problems of issues that arise'
'Early career; with basic skills development; work contributes to the success of team goals'
'Seasoned Professional; with a variety of technical skills developed; strong problem solver'
'Advanced; very senior; can solve most problems of issues that arise'
'Advanced; very senior; can solve most problems of issues that arise'
'Early career; with basic skills development; work contributes to the success of team goals'
",header=TRUE, stringsAsFactors=FALSE)
library(dplyr)
column1=df%>%
mutate(x=case_when(
.$x=="Seasoned Professional; with a variety of technical skills developed; strong problem solver" ~ 1,
.$x=="Entry-level; learning technical and professional skills" ~ 2,
.$x=="Early career; with basic skills development; work contributes to the success of team goals" ~ 3,
.$x=="Advanced; very senior; can solve most problems of issues that arise" ~ 4,
.$x=="Expert; has broad influence and experience within organization" ~ 5
))
column2=read.table(file.choose(),sep=",",header=TRUE)
data=data.frame(c(column1,column2))
mydata.cor = cor(data, method = c("spearman"))
Converting a string into a categorical number is exactly what factor()
does:将字符串转换为分类数正是factor()
所做的:
library(dplyr)
column1 = df %>%
mutate(x=factor(x))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.