Iterating through and manipulating a list of multiple dataframes one at a time

#sample image of dataframe within list

#code for reading in files within the folder
library(readxl)

library(tidyr)

setwd("C:/Users/Pimpjuice/Desktop/STOCK DATA MANIPULATION/SHORT TICKER FOLDER/ALL SHORT TICKER SHEETS")

my_files <- list.files(pattern = "*.xlsx")

my_files

df.list <- lapply(my_files, read_excel)

#packages and code for manipulating the data
install.packages("tibbletime")
install.packages("tsibble")
install.packages("lubridate")
library(tibbletime)
library(tidyverse)
library(tsibble)
library(dplyr)
library(lubridate)

#converting UNIX time stamp to Date time format and reformatting the Time zone
MARA5 <- MARA5 %>%
filter(MARA5$t != "t") %>%
mutate(t = as.numeric(t)) %>%
mutate(t = as_datetime(t, tz = "America/New_York"))

#removing duplicate values
MARA5 <- MARA5[!duplicated(MARA5$t), ]

#converting the 1 minute time series data into 30 minute increments
MARA5 <- MARA5 %>%
as_tsibble(index = t) %>%
index_by(t30 = ~ floor_date(., "30 minute")) %>%
summarise(open30 = first(o), close30 = last(c), min30 = min(l), max30 = max(h), volume30 = sum(v))

After the first step of reading in the files... The files are all existing within one data frame in the global environment. However, in the data frame, there are all of the files which can each be viewed individually. Within the data, frame created there are about 300 elements that represent each file from the folder. I am trying to iterate through each individual data frame within the object created and perform the above-mentioned data manipulation. I want to loop this process so that each data frame has is manipulated in the desired way and then exported as its own file.

I recommend you research the purrrr package.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.