Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

Forvalues loop in R: how to loop through data frames in R with name stubs and an identifying (consecutive) number

$
0
0

I would like to loop through data frames in R (each with the same name stub and a different identifying number/index at the end of the name) to create new dataframes with different name stubs and the same identifying number as the data frame it was created from.

Here is a link to the data: https://drive.google.com/drive/folders/14cGmcjGkYfr5X-ZE08uA71-X_wQiw_TY?usp=sharing

Below is the code for I would like, where [i] would be replaced by the consecutive ID number 1 through 204. Is there an elegant way to do this?

for (i in 1:204) {
ref[i] <- read.dta("F:/ref[i]pde.dta")
distref[i] <-osrmTable(loc=ref[i][1:length(ref[i]), c("pde","lon","lat")])
trips[i] <-osrmTable(loc=ref[i])
}

Viewing all articles
Browse latest Browse all 201919

Trending Articles