-1

The question is: Split the rows of clean_mlb into a training set consisting of 29 rows for the non- Pittsburgh teams and a testing set of one observation corresponding to the Pittsburgh Pirates. Save these dataframes as train set and test set.

clean_mlb is a dataframe that was made from a data set called mlb

Data Set MLB

Data Frame clean_mlb

This is my code:

  if(mlb$TM[i] == "PIT"){
    
  }else{

  }
} 

I wasn't sure what to put after the if or else or if this is even what I'm supposed to be doing.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Hannah
  • 9
  • 6
  • Please don't post screenshots of data. It's hard to provide good examples in solutions if there's no actual example data to work with. Post `dput(mlb)` or even a sample of `mlb` that contains a few examples of `TM == "PIT"` and its complement. – andrew_reece Nov 05 '20 at 04:46

1 Answers1

0

You can subset your data based on value in TM column.

train <- subset(mlb, TM != "PIT")
test <- subset(mlb, TM == "PIT")
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213