setwd(“C:\Users\ACAD\Desktop\police\xlsx”)
library(xlsx)
file.name<-c()
for (i in 1:1715) { temp <- paste(“test (”, i,sep=“”) temp <- paste(temp, “).xlsx”, sep=“”) file.name <- rbind(file.name, temp) }
file.name<-file.name[c(1:718, 729:1715)]
survey<-c()
for (i in file.name[1:500]) { temp <- read.xlsx(i, 1, colIndex=c(1,3), encoding=“UTF-8” ) names(temp) <- c(“res”,“qustion”) id <- rep(i, nrow(temp)) temp <- cbind(temp, id) survey <- rbind(survey, temp) }
write.csv(survey,“survey_xlsx_500.csv”)
survey<-c() for (i in file.name[501:1000]) { temp <- read.xlsx(i, 1, colIndex=c(1,3), encoding=“UTF-8” ) names(temp) <- c(“res”,“qustion”) id <- rep(i, nrow(temp)) temp <- cbind(temp, id) survey <- rbind(survey, temp) }
write.csv(survey,“survey_xlsx_1000.csv”)
survey<-c() for (i in file.name[1001:1715]) { temp <- read.xlsx(i, 1, colIndex=c(1,3), encoding=“UTF-8” ) names(temp) <- c(“res”,“qustion”) id <- rep(i, nrow(temp)) temp <- cbind(temp, id) survey <- rbind(survey, temp) } survey[94468,] write.csv(survey,“survey_xlsx_1715.csv”)
setwd(“C:\Users\ACAD\Desktop\police\xls”)
install.packages(“gdata”) library(xls) library(gdata) file.name<-c()
for (i in 1:134) { temp <- paste(“test (”, i,sep=“”) temp <- paste(temp, “).xls”, sep=“”) file.name <- rbind(file.name, temp) }
head(file.name)
file.name<-file.name[c(1:32,34:134)]
survey<-c()
for (i in file.name) { temp <- read.xlsx2(i, 1, colIndex=c(1,3)) names(temp) <- c(“res”,“qustion”) id <- rep(i, nrow(temp)) temp <- cbind(temp, id) survey <- rbind(survey, temp) }
write.csv(survey,“survey_xls.csv”)
survey.xls <- survey
head(survey.xls,20)
getwd() setwd(“C:/Users/ACAD/Desktop/tak”)
long <- read.csv(“long.csv”)
library(reshape2)
dcast(long, id~type)
long
sp <- read.csv(“F:\cloud\2015년 여름방학\sp_csv.csv”)
head(sp)
sp.test<-
sp[1:138,]
sp.short <- dcast(sp, id~question2)
head(sp.short,0)
sp2 <- read.csv(“F:\cloud\2015년 여름방학\sp_csv2.csv”)
names1 <- c() for (i in 1:1715) { temp <- paste(“test (”, i, sep=“”) temp <- paste(temp, “).xlsx”, sep=“”) names1 <- rbind(names1, temp) } head(names1) tail(names1)
names2 <- c() for (i in 1:134) { temp <- paste(“test (”, i, sep=“”) temp <- paste(temp, “).xls”, sep=“”) names2 <- rbind(names2, temp) } head(names2) tail(names2)
names <- append(names2, names1) head(names, 150) tail(names)
var <- as.vector(read.csv(“var.csv”, header=FALSE))
var <- var[,1] var
length(names)
sp.short <- c()
for(i in 1:1849) { id.temp <- rep(names[i], 70)
temp <- data.frame(id.temp, var) sp.short <- rbind(sp.short, temp) } names[1715] tail(sp.short) head(sp.short)
write.csv(sp.short, “var_key.csv”)
sp <- read.csv(“C:\Users\ACAD\Desktop\tak\var_key_long.csv”)
head(sp)
sp.temp <- sp[1:210,] tail(sp.temp)
sp.long <- dcast(sp, id.temp ~ var)
write.csv(sp.long, “sp.long.csv”)
sp.long <- c()
for(i in 1:3) { for (j in 1:70) { temp <- sp[i,] sp.long <- rbind(sp.long, temp)
} }
temp <- sp.long[1:70,2:3] head(sp)