Severe "Unknown or Uninitialized Column: " error

I am trying to do some modeling of crop yield data using weather data. I have created a list of data models in a tibble, similar to how Hadley does his in his "managing many models" tutorial. However, I am running into a severe Unknown or Uninitialized Column error, which now occurs with half or more of the lines of code I run.
Here is the beginning of my code, and then I show 8 lines that create the nested tibbles in each row/column of the giant tibble that contains the models.

        corn <- read.csv('I:\\HATCH_Project\\Corn.csv')
    corn <- corn[corn$Single == 'Yes',]
    corn$County[which(corn$County == 'Mcpherson')] <- 'McPherson'
    corn$County[which(corn$County == 'Mccook')] <- 'McCook'
    corn_df_values <- data.frame(corn$Year,corn$County,corn$Value); colnames(corn_df_values) <- c('Year','County','Yield')
    corn_final <- corn_df_values %>% pivot_wider(names_from = County, values_from = Yield)
    corn_final <- corn_final[order(corn_final$Year),]
    corn_final_wide <- corn_final %>% tibble %>% select("Year", sort(colnames(.)))
    corn_final_long <- corn_final_wide %>% pivot_longer(!Year, names_to = 'County', values_to = 'Yield')
    corn_final_long <- corn_final_long[-which($Yield)),]
    corn_by_county <- corn_final_long %>% group_by(County) %>% mutate(n = n())
    corn_by_county <- corn_by_county %>% group_by(County,n) %>% nest()
    gdd_runsum_df <- tibble(Date = seq(as.Date('2020-04-01'),as.Date('2020-11-01'),by='day'))
    gdd_runsum_df$month <- month(gdd_runsum_df$Date); gdd_runsum_df$day <- day(gdd_runsum_df$Date)
    gdd_runsum_df$runsum1 <- NA; gdd_runsum_df$runsum5 <- NA; gdd_runsum_df$runsum10 <- NA; gdd_runsum_df$runsum15 <- NA; gdd_runsum_df$runsum20 <- NA; 
    gdd_runsum_df$runsum25 <- NA; gdd_runsum_df$runsum30 <- NA; gdd_runsum_df$runsum35 <- NA; gdd_runsum_df$runsum40 <- NA; gdd_runsum_df$runsum45 <- NA;
    gdd_runsum_df$runsum50 <- NA; gdd_runsum_df$runsum60 <- NA; gdd_runsum_df$runsum70 <- NA; gdd_runsum_df$runsum75 <- NA; gdd_runsum_df$runsum80 <- NA; gdd_runsum_df$runsum90 <- NA;
    gdd_runmean_df <- tibble(Date = seq(as.Date('2020-04-01'),as.Date('2020-11-01'),by='day'))
    gdd_runmean_df$month <- month(gdd_runmean_df$Date); gdd_runmean_df$day <- day(gdd_runmean_df$Date)
    gdd_runmean_df$runmean1 <- NA; gdd_runmean_df$runmean5 <- NA; gdd_runmean_df$runmean10 <- NA; gdd_runmean_df$runmean15 <- NA; gdd_runmean_df$runmean20 <- NA; 
    gdd_runmean_df$runmean25 <- NA; gdd_runmean_df$runmean30 <- NA; gdd_runmean_df$runmean35 <- NA; gdd_runmean_df$runmean40 <- NA; gdd_runmean_df$runmean45 <- NA;
    gdd_runmean_df$runmean50 <- NA; gdd_runmean_df$runmean60 <- NA; gdd_runmean_df$runmean70 <- NA; gdd_runmean_df$runmean75 <- NA; gdd_runmean_df$runmean80 <- NA; gdd_runmean_df$runmean90 <- NA;

Please let me know if I am doing something wrong here. I asked this on Stack Overflow (, but no answers came. My nested tibble is 271 columns wide, and 66 rows long. Maybe it's just too big. I don't know. But I know this error is really starting to wear on me. Please help:) Thank you.

Hi @rbehnke,
Welcome to the RStudio Community Forum.

Placing multiple R functions on a single line each separated by ; is possible but can lead to lots of confusion and errors (as in your case).
I think you want to add columns with a simple pattern of column names, all filled with NA.
This code will do that and should get you started:


gdd_runsum_df <- tibble(Date = seq(as.Date('2020-04-01'), as.Date('2020-11-01'), by='day'))
gdd_runsum_df$month <- month(gdd_runsum_df$Date)
gdd_runsum_df$day <- day(gdd_runsum_df$Date)

new_vars <- c(paste0("runsum", c(1,5,seq(10, 90, by=5))))
gdd_runsum_df[,new_vars] <- NA


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.

Thank you! Works much better now.