I am having trouble removing selected data from a data set. I have an example of the set, and I have another table of selected rows (toremove). I am trying to remove (toremove) from the the original set.
I tried to use setdiff, but while there were rows cut dow (according to environment variables), it was not the selected data removed.
Prod1<- Prod[setdiff(rownames(Prod),rownames(toremove )),]
Example of entire dataset in dput:
Prod <- structure(list(CountryCode = c(5000L, 5300L, 5300L, 5000L, 5400L,
5300L, 5400L, 5200L, 5200L, 5200L, 5000L, 5000L), Country = structure(c(4L,
2L, 2L, 4L, 3L, 2L, 3L, 1L, 1L, 1L, 4L, 4L), .Label = c("Americas + (Total)",
"Asia + (Total)", "Europe + (Total)", "World + (Total)"), class = "factor"),
ItemCode = c(1814L, 1717L, 1817L, 116L, 1717L, 1817L, 1817L,
156L, 1717L, 1817L, 1735L, 1800L), Item = structure(c(3L,
2L, 1L, 4L, 2L, 1L, 1L, 5L, 2L, 1L, 6L, 7L), .Label = c("Cereals (Rice Milled Eqv) + (Total)",
"Cereals,Total + (Total)", "Coarse Grain, Total + (Total)",
"Potatoes", "Sugar cane", "Vegetables Primary + (Total)",
"Vegetables&Melons, Total + (Total)"), class = "factor"),
ElementGroup = c(31L, 31L, 31L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L), ElementCode = c(5312L, 5312L, 5312L,
5510L, 5510L, 5510L, 5510L, 5510L, 5510L, 5510L, 5510L, 5510L
), Element = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L), .Label = c("Area harvested", "Production"
), class = "factor"), Unit = structure(c(1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Ha", "tonnes"
), class = "factor"), Y1961 = c(3.29e+08, 2.72e+08, 2.72e+08,
2.71e+08, 2.64e+08, 2.63e+08, 2.63e+08, 2.36e+08, 2.28e+08,
2.24e+08, 2.23e+08, 2.23e+08), Y1962 = c(3.27e+08, 2.76e+08,
2.76e+08, 2.53e+08, 2.81e+08, 2.78e+08, 2.81e+08, 2.22e+08,
2.4e+08, 2.36e+08, 2.23e+08, 2.23e+08), Y1963 = c(3.33e+08,
2.76e+08, 2.76e+08, 2.7e+08, 2.5e+08, 2.95e+08, 2.49e+08,
2.26e+08, 2.62e+08, 2.58e+08, 2.23e+08, 2.23e+08), Y1964 = c(3.29e+08,
2.82e+08, 2.82e+08, 2.85e+08, 2.96e+08, 3.1e+08, 2.96e+08,
2.43e+08, 2.49e+08, 2.45e+08, 2.26e+08, 2.26e+08)), .Names = c("CountryCode",
"Country", "ItemCode", "Item", "ElementGroup", "ElementCode",
"Element", "Unit", "Y1961", "Y1962", "Y1963", "Y1964"), class = "data.frame", row.names = c(NA,
-12L))
Selected data to remove:
toremove <- structure(list(CountryCode = c(5000L, 5400L, 5300L, 5400L, 5200L
), Country = structure(c(4L, 3L, 2L, 3L, 1L), .Label = c("Americas + (Total)",
"Asia + (Total)", "Europe + (Total)", "World + (Total)"), class = "factor"),
ItemCode = c(116L, 1717L, 1817L, 1817L, 1717L), Item = structure(c(3L,
2L, 1L, 1L, 2L), .Label = c("Cereals (Rice Milled Eqv) + (Total)",
"Cereals,Total + (Total)", "Potatoes"), class = "factor"),
ElementGroup = c(51L, 51L, 51L, 51L, 51L), ElementCode = c(5510L,
5510L, 5510L, 5510L, 5510L), Element = structure(c(1L, 1L,
1L, 1L, 1L), .Label = "Production", class = "factor"), Unit = structure(c(1L,
1L, 1L, 1L, 1L), .Label = "tonnes", class = "factor"), Y1961 = c(2.71e+08,
2.64e+08, 2.63e+08, 2.63e+08, 2.28e+08), Y1962 = c(2.53e+08,
2.81e+08, 2.78e+08, 2.81e+08, 2.4e+08), Y1963 = c(2.7e+08,
2.5e+08, 2.95e+08, 2.49e+08, 2.62e+08), Y1964 = c(2.85e+08,
2.96e+08, 3.1e+08, 2.96e+08, 2.49e+08)), .Names = c("CountryCode",
"Country", "ItemCode", "Item", "ElementGroup", "ElementCode",
"Element", "Unit", "Y1961", "Y1962", "Y1963", "Y1964"), class = "data.frame", row.names = c(NA,
-5L))