我想分析使用surveymonkey创建的大型调查,该调查在CSV文件中有数百列,输出格式很难用作两行标题。使用R解析出Surveymonkey csv文件
- 有没有人找到一种管理CSV文件中头文件的简单方法,以便分析是可管理的?
- 其他人如何分析Surveymonkey的结果?
谢谢!
我想分析使用surveymonkey创建的大型调查,该调查在CSV文件中有数百列,输出格式很难用作两行标题。使用R解析出Surveymonkey csv文件
谢谢!
我到底做了什么是打印出来使用标注为V1,V2,等等,那么我刚才读的文件中的LibreOffice标题为
m1 <- read.csv('Sheet1.csv', header=FALSE, skip=1)
,然后就做对抗M1 $ V10分析,M1 $ V23等..
为了解决多个列的一塌糊涂我用下面的小功能
# function to merge columns into one with a space separator and then
# remove multiple spaces
mcols <- function(df, cols) {
# e.g. mcols(df, c(14:18))
exp <- paste('df[,', cols, ']', sep='', collapse=',')
# this creates something like...
# "df[,14],df[,15],df[,16],df[,17],df[,18]"
# now we just want to do a paste of this expression...
nexp <- paste(" paste(", exp, ", sep=' ')")
# so now nexp looks something like...
# " paste(df[,14],df[,15],df[,16],df[,17],df[,18] , sep='')"
# now we just need to parse this text... and eval() it...
newcol <- eval(parse(text=nexp))
newcol <- gsub(' *', ' ', newcol) # replace duplicate spaces by a single one
newcol <- gsub('^ *', '', newcol) # remove leading spaces
gsub(' *$', '', newcol) # remove trailing spaces
}
# mcols(df, c(14:18))
毫无疑问会有人能打扫一下!
收拾我用李克特状鳞屑:
# function to tidy c('Strongly Agree', 'Agree', 'Disagree', 'Strongly Disagree')
tidylik4 <- function(x) {
xlevels <- c('Strongly Disagree', 'Disagree', 'Agree', 'Strongly Agree')
y <- ifelse(x == '', NA, x)
ordered(y, levels=xlevels)
}
for (i in 44:52) {
m2[,i] <- tidylik4(m2[,i])
}
随意,因为没有疑问,这将再次拿出来发表评论!
您可以将其导出,从Surveymonkey适合R A方便的形式,请参阅“高级表格格式的下载响应
2013年11月,网页布局似乎已经改变。选择Analyze results > Export All > All Responses Data > Original View > XLS+ (Open in advanced statistical and analytical software)
。然后转到导出并下载文件。你会得到原始数据作为第一行=问题标题/每个行= 1响应,如果你有很多回复/问题,可能会在多个文件之间分割。
问题与头是与“选择所有适用的”列将有一个空白顶行和列标题将低于该行。这只是这些类型问题的一个问题。
考虑到这一点,我写了一个循环来遍历所有列,并从第二行的值,如果列名是空白字符其中有1
一个字符长度,然后更换列名,你可以杀死第二行数据并且有一个整齐的数据框。
for(i in 1:ncol(df)){
newname <- colnames(df)[i]
if(nchar(newname) < 2){
colnames(df)[i] <- df[1,i]
}
df <- df[-1,]
你可以发表一个*小* Surveymonkey输出的例子来说明问题吗?我可以想象一个解决方案,它使用'readLines'和'n = 2'来读取(并按摩)标题,并使用'read'。csv' with'skip = 2,header = FALSE'来获取数据... –
下一次当您运行调查时,使用LimeSurvey(http://www.limesurvey.org/) - 它是开源的,它有一个出口到R设施,工作相当好(披露:我写了出口模块) – Andrie
@Ben,文件中的标题是两行问题名称/编号,然后在下面的行写出子问题。一般来说,在屁股处理的总痛苦。 –