I\'m trying to apply this function to mutiple files and save them. Any help with
ID: 3789700 • Letter: I
Question
I'm trying to apply this function to mutiple files and save them. Any help with this? I get an error with the paste0 function not being found. I just have some statsistics i would like to run on mutilple sets of files. The problem is my statistics are somewhat hard to run apparently with a function. Not sure why...i'm not an expert with R and somewhat doing this for fun. thanks
#Function for summary statistics
Batchfile<- function(folder1, folder2){
inputDir = paste0(getwd(),"/",folder1,"/")
outputDir=Paste0(getwd(),"/",folder2,"/")
Stats <- function(YC){
names(YC)
str(YC)
summary(YC) #summary stat
pairs(YC) #basic scatterplot matrix
cor(YC) #determines correlations b/w 2 variables
par(mar=rep(2,4))
boxplot(YC) #indicates if variables differ in magnitiude and that they have different variances
library(MVN)
uniNorm(YC, type="SW", desc=TRUE) #gets the shapiro-wilks test of univariate normality along w/ descriptive stats like skewness and kurtosis
par(mar=rep(2,4))
uniPlot(YC, "histogram") #visulization step
result<-mardiaTest(YC, qqplot=T)#to get all plot within the same frame
result
return(YC)
}
filenames <- list.files(inputDir, pattern = "CodaBrundage")
inputFiles<-lapply(paste0(inputDir, filenames), read.csv)
manipulated<-lapply(inputFiles, Stats)
names(manipulated)<-gsub(".csv",".results",filenames)
lapply(names(manipulated), function(x)write.csv(manipulated[[x]],
file.paste0(outputDir,x,".csv"), row.names=F))
}
Batchfile("in","out")
Explanation / Answer
You need to check for 2 things