-3

I have data about baseball result in 2016.

Example

Now, I want to remove the column that made tie score.

That is, I want to remove the column that has same value in $team1_score and $team2_score.

How can I use the function in r?

I just tried to use the following code, but it didn't work well.

Baseball2 <- Baseball[!duplicated(Baseball$team1_score)]

Please help me...!!

Adam Quek
  • 6,973
  • 1
  • 17
  • 23
Hailey
  • 9
  • 2
  • what went wrong... – MichaelChirico May 08 '17 at 05:36
  • 1
    Why is it today that everybody is posting *images of data*? Please, Hailey, post **data**, not an image of it. Please read (or reread) about [reproducible questions](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), especially areas where it provides options for including usable data in your question. – r2evans May 08 '17 at 05:37
  • ... and in this problem, you'll need to identify what the intended output should be. Removing a whole column does not make sense to me. And since none of this data shows duplication in teams/scores, it seems insufficient to demonstrate your point. – r2evans May 08 '17 at 05:39
  • I'm not sure if the question is on dealing with duplicated data. Suggest to remove `duplicates` tag and revise the question title. – Adam Quek May 08 '17 at 05:41
  • I've never uploaded any actual file, so that is why I just captured and uploaded the image. There are so many data like above image and a few scores were tie in above data. I just wanted to remove the column that has tie score . – Hailey May 08 '17 at 05:45

2 Answers2

0

Here's an simple way to remove rows with tie-score:

(dat <- data.frame(Team1_Score= c(1,2,3), Team2_Score=c(2,3,3)))

  Team1_Score Team2_Score
1           1           2
2           2           3
3           3           3

Use logical test to find which row has tie score:

tie <- dat$Team1_Score == dat$Team2_Score
tie
[1] FALSE FALSE  TRUE

Use this result to select rows that are not tie:

dat[!tie, ]

  Team1_Score Team2_Score
1           1           2
2           2           3
Adam Quek
  • 6,973
  • 1
  • 17
  • 23
0

I understand you do not want to remove duplicates, but need to subset the dataframe discarding tied matches.

A very simple option using data.table:

library(data.table)
Baseball2 <- data.table(Baseball)
Baseball2 <- Baseball2[Team1_Score != Team2_Score,]
COLO
  • 1,024
  • 16
  • 28