I am new to R and am trying to access data outside a loop
# List of 100 stock data
a <-c ("one", "two", "three", "four",...)
i = 1
while (i <= length(a)) {
# make a list_element.csv to be accessed from local storage
formated_path <-paste(a[i], ".csv")
if (!file.exists(formated_path)) {
output <- paste("Data for ", a[i], "Not found!")
print(output)
} else {
print("found")
a[i] <- read.csv(formated_path, header = TRUE)
# I have tried to change the name of the array to
# correspond to the element name but no luck as
paste(a[i], "_stock") <-read.csv(formated_path, header = TRUE)
return(a[i])
i = i + 1
}
}
My desired outcome is to be able to use the individually loaded .csv
s with other functions outside the loop. I do not desire a multidimensional array, just individual arrays corresponding to the array element as:
# Desired output
print(one) # Should be the elements of a