I am working on R Studio.
I have ~50 txt files, all of which have data in similar format (14 col's in same order). Each file is large (~100MB). I have all the files saved in one folder. What I need to do it write an R code so that I can open one file, perform some operations, write the output to target file and close the file. After this I need to follow the process for the remaining files. I wanted to automate the process, but unsure on how to proceed with the same. Tried searching, but could not come across something that I could apply.
I have done this for one file, but not sure of the code that could help me automate the process for 50 files. Requesting help.....
library(data.table)
library(dplyr)
library(tidyverse)
#### Opening One File
myfile=fread("C:/Users/shegu/Desktop/LOB30SCRIP_010318.txt",
sep="|",header=FALSE, stringsAsFactors = TRUE)
#### Renaming cols
colnames(myfile) <- c("Trading_Session", "Scrip_Code", "Buy_Sell",
"Order_Type", "Rate_in_Paise", "Quantity","Avl_Quantity", "Order_Time_Stamp",
"Retention", "AUD_Code", "Order_ID", "Action_ID", "Error_Code","ALGO_Flag")
#### Changing Format of cols
myfile$Order_Time_Stamp=as.Date(myfile$Order_Time_Stamp, "%Y-%m-%d %H:%M:%S")
myfile$Scrip_Code=as.factor(myfile$Scrip_Code)
myfile$Order_ID=as.factor(myfile$Order_ID)
#### Performing Group-by operation (this needs to be done on each file in my folder)
myfile_by_AUD_Code=myfile%>%
group_by(Scrip_Code,ALGO_Flag,AUD_Code)%>%
summarise(n())
#### Writing results to target file (need results for all files in this target file)
write.csv(myfile_by_AUD_Code,"C:/Users/shegu/Desktop/BSE_Data/Target.csv",
row.names = FALSE)