I'm trying to create a new data frame out of only specific rows from my existing data frame. First, I imported the dataset, and then I did this
read.csv("testvdemset.csv")
The code I'm using to create the new data frame is
data <- testvdemset %>%
-
filter(country_name =='Argentina','Bolivia','Ecuador','Guatemala','Haiti','Honduras','Panama','Paraguay','Peru','Venezuela')
However, it returns this message
Error in `filter()`:
! Problem while computing ..2 = "Bolivia"
.
x Input ..2
must be a logical vector, not a character.
Run rlang::last_error()
to see where the error occurred.
Without changing anything, I'll run it again and get this
Error in filter(country_name == "Argentina", "Bolivia", "Ecuador", "Guatemala", :
object 'country_name' not found
And that also happens when I do make changes. When I use exists() for country_name, it says that it does not exist, nor do any of the other variables (columns) in my existing data frame. I made sure that my working directory was correct and that there are no spelling/capitalization errors. What am I doing wrong and how can I fix this? Thank you!!
CodePudding user response:
Try this
data <- testvdemset %>%
filter(country_name %in% c('Argentina','Bolivia','Ecuador','Guatemala','Haiti','Honduras',
'Panama','Paraguay','Peru','Venezuela'))