I have a very messy data frame consisting of factor columns with numbers and characters. I need to filter the rows with numeric values above a threshold. However, this is a problem because my columns are factors that cannot be turned to numeric, due to the presence of characters in them.
DF <- data.frame(
Col1 = c("Egg", "", "3"),
Col2 = c("", "Flour", ""),
Col3 = c("2", "", "Bread"),
Col4 = c("4", "", ""),
Col5 = c("", "6", "8")
)
The resulting data frame looks like this:
> DF
Col1 Col2 Col3 Col4 Col5
1 Egg 2 4
2 Flour 6
3 3 Bread 8
Where each column is a factor:
> class(DF$Col1)
[1] "factor"
>
In this example, how do I filter rows with numeric values above, say, 5 in at least one column? The desired output in this example, looks like this:
> DF
Col1 Col2 Col3 Col4 Col5
2 Flour 6
3 3 Bread 8