0

I have a data frame which has two columns 'Place' and 'Visits'. I want only those rows for which has same 'Place' values. For example if the data frame is like this:

Place  Visits
China     23
China     48
London    234
Paris     34
Boston    534
Boston    34

I want these rows only after the operation:

Place  Visits
China     23
China     48
Boston    534
Boston    34

How can I accomplish this in R? I tried using duplicated but it is not giving me the correct results.

Jaap
  • 81,064
  • 34
  • 182
  • 193
Rahul Jain
  • 67
  • 1
  • 2
  • 8
  • 1
    How did you use `duplicated` and what did it return? Did you read `help("duplicated")` carefully? – talat Feb 26 '16 at 21:53
  • I used `duplicated` like this: `df[duplicated(df),]` – Rahul Jain Feb 26 '16 at 22:00
  • Assuming `dat` is your data.frame, you could use: `dat[dat[,1] %in% unique(dat[,1][ duplicated(dat[,1])]),]` – count Feb 26 '16 at 22:03
  • As the answer in the duplicate question tells, you can use `df[duplicated(df$Place) | duplicated(df$Place, fromLast = TRUE), ]` – talat Feb 26 '16 at 22:05

0 Answers0