I need help to modify my code to do the following tasks... I've used help from the following questions and answers thus far
Here are things i hope to be able to do with my code...
- I need to read in several files from a folder
- I will like to use the name of each of the files in the folder to add a column. I was able to do this simply with 'mutate' but for a single file
- I will like to save the result of each file separately and also combine to a single file
- I also want to keep the code for reading the files separate from the function, so i can apply to other projects.
- I'm trying to avoid using the 'loop' statements
Here is the sample of my incomplete code which gives error
library(tidyverse)
library(readr)
cleaningdata<- function(data){
data$Label<-gsub(".tif", "", data$Label)
data %>% select(Label:Solidity) %>%group_by(Label)%>%
mutate(view = seq_along(Label), Station="T1-1")%>%
rename(Species = Label)%>%
mutate(view = recode(view, "1" = "a","2" = "b","3" = "c"))
}
filenames <- list.files("Data", pattern="*.txt", full.names=TRUE)
ldf <- lapply(filenames, read.txt)
res <- lapply(ldf, cleaningdata)
Here is a sample of my dataset Data Folder and below is my work thus far