I've done a quick search on this topic but haven't found anything from previous posts to address my question. It seems very straight forward but I've still not figured out how to do this efficiently.
In the data frame below, I'd like to delete all rows with a single entry (In this case B500
and D40
).
x_1 <- c("A1", "A1","A1", "B10", "B10", "B10","B10",
"B500", "C100", "C100", "C100", "D40", "G100", "G100")
z_1 <- rnorm(14, 70)
z_2 <- rnorm(14, 1.7)
A <- data.frame(x_1, z_1, z_2)
x_1 z_1 z_2
1 A1 69.65033 1.5308858
2 A1 68.72687 2.2859416
3 A1 68.32700 0.7994794
4 B10 68.68382 0.5212132
5 B10 70.23359 1.3266729
6 B10 70.68604 4.3823605
7 B10 70.52774 2.2430322
8 B500 69.62868 3.0121398
9 C100 69.41412 2.1895905
10 C100 69.10745 1.7599065
11 C100 69.70876 1.6001099
12 D40 68.96542 0.7485665
13 G100 70.21754 1.9635395
14 G100 72.70583 3.0645247
I can do this manually by using:
A[!A$x_1 %in% c("B500", "D40"), ]
Another way of doing this is using the table function below:
table(A$x_1)
A1 B10 B500 C100 D40 G100
3 4 1 3 1 2
Now, my problem is how do I select the entries with just the number 1 underneath them? If I can do this, I should be able to get the names and then delete them from the data frame.
Any useful ideas/codes would be highly appreciated.