0

I've entered my data into R using the following command...

Country_Data <- read.csv("Country Data.csv", row.names = 1)

With the following result...

               Criteria 1    Criteria 2    Criteria 3
[Country A]        x             x              x
[Country B]        x             x              x
[Country C]        x             x              x
...
[Country Z]        x             x              x

In the process of my coding I created a subset influential_countries similar to the following...

           Criteria 4    
[Country E]        x     
[Country F]        x       
[Country J]        x       

I would like to delete this subset of countries from Country_Data. In other words, I would like to remove Countries E, F, and J. I attempted the following code without much luck...

Country_Data_clean <- Country_Data[-c(influential_countires), ]

Any suggestions on how to remove would be greatly appreciated!

wibeasley
  • 5,000
  • 3
  • 34
  • 62
gravityflyer
  • 119
  • 5
  • 2
    Try with `anti_join` if it is a column. or else `Country_Data[!row.names(Country_Data) %in% row.names(influential_countries),]`\ – akrun Jul 06 '18 at 03:27
  • Thank you, but I actually tried that command based on a previous search and still no luck. Nothing was deleted from Country_Data. – gravityflyer Jul 06 '18 at 03:41
  • If the commented code didn't work, and none of the five answers provided in the duplicate questions worked, then the impetus is on you to provide a [reproducible question](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including consumable data (yours is close), what code you tried, and what your actual results are. – r2evans Jul 06 '18 at 03:50
  • Thank you for the assistance. Would this count as a reproducible data? `data(mtcars) subset<-subset(mtcars, mpg >= quantile(mtcars$mpg)[4]) mtcars[!row.names(mtcars) %in% row.names(subset),] ` – gravityflyer Jul 06 '18 at 04:00
  • So I was successful in getting this code to achieve my desired outcome in the reproducible data, `df <- mtcars[!(rownames(mtcars) %in% rownames(subset )),]` But could not get it to work in my own data set. Hmmm... – gravityflyer Jul 06 '18 at 04:30
  • That does count as reproducible data, but apparently it isn't *good* meaningful data. That is, it does not representative of what you need. It could be due to `factor`s, lack of row names, or several other things. Unless and until you provide actual consumable data (read the link), however, there's nothing we can do. – r2evans Jul 06 '18 at 05:38

0 Answers0