I have a written a function in r markdown. I want to run the below on a number of different csvs stored in the same folder.
How would I therefore go about creating a generic function [in place of the below code within my overall code] so that it allowed for the import and analysis of each of the csvs in the folder?
dat <- read.csv("importsinglecsv.csv",
header = TRUE,
sep=',')
Overall code outlined below:
Single Test
dat <- read.csv("importsinglecsv.csv",
header = TRUE,
sep=',')
datA <- subset(dat, Version == "A")
datB <- subset(dat, Version == "B")
olsA <- lm(measure ~ mark, data = datA)
olsB <- lm(measure ~ mark, data = datB)
coeffs <- rbind(olsA$coefficients, olsB$coefficients)
r.Squared <- rbind(summary(olsA)$r.squared, summary(olsB)$r.squared)
corA <-cor(datA$measure, datA$mark)
corB <- cor(datB$measure, datB$mark)
```
I've tried to develop a for loop linking to the markdown file, but have done something wrong.....
for (i in length(df)) {
dat <- df[[i]]
datA <- subset(dat, Version == "A")
datB <- subset(dat, Version == "B")
rmarkdown::render('"filepath"/tes.rmd',
output_file=paste0("filepath", df[i], ".html"),
params=list(new_title=paste("Exploratory analysis -", i)))
}