# This file exports RDS-files to CSV-format # Importing libraries .packages <- c("tidyverse", "tm", "tidytext", "fuzzyjoin", "widyr", "wordcloud2") .inst <- !(.packages %in% installed.packages()) install.packages(.packages[.inst], dependencies = T) lapply(.packages, require, character.only = T) library(data.table) # # Importing and Re-strucutring the data from the CBMC's setwd("C:/Users/lankp/surfdrive/documents/promotie/werkmap/Article 5 Serious Game/2_analyse/Extraction Results") game_pre <- readRDS('game_prep.rds') %>% mutate(Group = 'game_pre', GroupWide = 'game') game_post <- readRDS('game_iter.rds') %>% mutate(Group = 'game_post', GroupWide = 'game') control_pre <- readRDS('cont_prep.rds') %>% mutate(Group = 'control_pre', GroupWide = 'control') control_post <- readRDS('cont_iter.rds') %>% mutate(Group = 'control_post', GroupWide = 'control') #sapply(game_pre, class) #function to remove lists from dataframe set_lists_to_chars <- function(x) { if(class(x) == 'list') { y <- paste(unlist(x),sep="")#, recursive = TRUE, use.names = TRUE) } else { y <- x } return(y) } ###game-pre to csv game_pre2 <- data.frame(lapply(game_pre, set_lists_to_chars), stringsAsFactors = F) #sapply(game_pre2, class) game_pre2[] <- lapply(game_pre2, gsub, pattern = "\r\n", replacement = "", fixed = TRUE) write.table(game_pre2, file="game_pre.csv", append = FALSE, sep = ";", dec = ".", row.names = TRUE, col.names = TRUE) ###game-post to csv game_post2 <- data.frame(lapply(game_post, set_lists_to_chars), stringsAsFactors = F) game_post2[] <- lapply(game_post2, gsub, pattern = "\r\n", replacement = "", fixed = TRUE) write.table(game_post2, file="game_post.csv", append = FALSE, sep = ";", dec = ".", row.names = TRUE, col.names = TRUE) ###control-pre to csv control_pre2 <- data.frame(lapply(control_pre, set_lists_to_chars), stringsAsFactors = F) control_pre2[] <- lapply(control_pre2, gsub, pattern = ";", replacement = ",", fixed = TRUE) control_pre2[] <- lapply(control_pre2, gsub, pattern = "-", replacement = "", fixed = TRUE) control_pre2[] <- lapply(control_pre2, gsub, pattern = " ", replacement = " ", fixed = TRUE) control_pre2[] <- lapply(control_pre2, gsub, pattern = "\r\n", replacement = "", fixed = TRUE) write.table(control_pre2, file="control_pre.csv", append = FALSE, sep = ";", row.names = TRUE, col.names = TRUE) ###control-post to csv control_post2 <- data.frame(lapply(control_post, set_lists_to_chars), stringsAsFactors = F) control_post2[] <- lapply(control_post2, gsub, pattern = ";", replacement = ",", fixed = TRUE) control_post2[] <- lapply(control_post2, gsub, pattern = "\r\n", replacement = "", fixed = TRUE) write.table(control_post2, file="control_post.csv", append = FALSE, sep = ";", row.names = TRUE, col.names = TRUE)