$ operator is invalid for atomic vectors for dataframe R

The problem is relatively simple. You have

team_seed <- data.frame()
team_seed <- cbind(playoff_teams, seed_col, BPI_col) 

If we break this down you’ll see the problem:

  1. You create an empty data frame and assign it to the object team_seed
  2. You create a matrix by column-binding the vectors playoff_teamsseed_col, and BPI_col.
  3. You assign this matrix to the object team_seed, thus obliterating the empty data frame you created in the first line. R just overwrote it.
  4. You then try to head() a component of team_seed but R rightly complains that this is an atomic vector (a matrix is a vector with a dim attribute)

What you want is some variation on:

team_seed <- data.frame(playoff_teams, seed_col, BPI_col)

there is no reason to allocate the empty data frame. If you do that, then you need to fill in the data frame, not overwrite it.

Leave a Comment