Qualtrics and R: Quick Way to do Summary Statistics of Demographics in Character values

Qualtrics and R: Quick Way to do Summary Statistics of Demographics in Character values

from Qualtrics export text choice Excel
R code to replace Likert values

#clean Likert scale

# List of replacements

replacements <- list(

"Strongly Disagree (1)" = 1,

"Disagree (2)" = 2,

"Slightly Disagree (3)" = 3,

"Neutral (4)" = 4,

"Slightly Agree \r\n (5)" = 5,

"Slightly Agree (5)" = 5,

"Agree (6)" = 6,

"Strongly Agree (7)" = 7

)

# Function to replace values in a vector

replace_values <- function(x, replacements) {

for (key in names(replacements)) {

x[x == key] <- replacements[[key]]

}

return(x)

}

# Applying the function only to relevant columns

data <- data.frame(lapply(data, function(column) {

if (any(column %in% names(replacements))) {

as.numeric(replace_values(column, replacements))

} else {

column

}

}))

# Checking if the replacements worked

head(data)




R code for summary statistics for characters

#Summary demographics

table(data$gender)

prop.table(table(data$gender))

table(data$age)

prop.table(table(data$age))

table(data$educ)

prop.table(table(data$educ))

table(data$employ)

prop.table(table(data$employ))



要查看或添加评论,请登录

Yuqi Wang Prof. Ph.D.的更多文章

社区洞察

其他会员也浏览了