0

Having an issue with binding in R. Ive' created the NULL df and created a loop to import multiple files and bind them to the null df. However, my df is still null after this process. Not sure what I am missing. I ran each individual line and also sourced it and still same result.

library(readr)

    df <- NULL

    gamenumbers <- c(20001:20003)

    for(game in gamenumbers){

      filename<-paste0('C:/Users/mike/Google Drive/model_code/TEST2/2017', game, '/', game)

      pbp_df <- read_delim(filename, delim = '|') 

      rbind(df, pbp_df)

    }

enter image description here

Michael T Johnson
  • 679
  • 2
  • 13
  • 26
  • 1
    You didn't save the results of `rbind()` anywhere. Functions do not modify variables in place. They return updated objects. Be sure to save the result, ie `df <- rbind(df, pbp_df)`. But rbind-ing one at a time is not very efficient. Better to create a list with `lappy` and `rbind` at the end. – MrFlick Aug 20 '18 at 19:06
  • 1
    The duplicate shows both methods properly. – MrFlick Aug 20 '18 at 19:07
  • Thank you MrFlick! – Michael T Johnson Aug 20 '18 at 19:13

0 Answers0