简体   繁体   English

有没有更简单的方法可以在 R 中找到分类数据和多列数值数据之间的相关性?

[英]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.

相关问题 R程序可视化+如何在分类数据和数值数据之间进行绘图 - R program visualization + How to plot between categorical and numerical data 所选列与 R 中 data.frame 的其余部分之间的相关性 - Correlations between the selected column and the rest of the data.frame in R 分类和数值数据的聚类 - Clustering for Categorical and Numerical data sparseMatrix与数值和分类数据 - sparseMatrix with numerical and categorical data 根据另一个字符列(R)中的分类数据,使用聚合对数字变量求和 - Using aggregate to sum a numerical variable, according to categorical data in another character column (R) 寻找 R 功能将数据框中的数字列拆分为具有 3 个级别的分类变量 - Looking for R functionality to split a numerical column in a data frame into a categorical variable with 3 levels 找出r中分类数据的差异 - Find difference of categorical data in r R:在数据框中替换多个列名并保留其数值 - R: substitute multiple column names in a data frame and keep their numerical value 如何在R中使用vioplot绘制分类数据与数值数据? - How to plot categorical vs numerical data with vioplot in R? 如何使用分类和数值数据is R创建分层集群? - How to create a hierarchical cluster using categorical and numerical data is R?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM