PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 30, 2022

[FIXED] What do I do to correct Error in `filter()` and then 'object not found'?

 August 30, 2022     csv, dataframe, filter, r     No comments   

Issue

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!!


Solution

Try this

data <- testvdemset %>% 
  filter(country_name %in% c('Argentina','Bolivia','Ecuador','Guatemala','Haiti','Honduras',
                         'Panama','Paraguay','Peru','Venezuela'))


Answered By - user16087142
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing