Trying filter function

Hello everyone,

When i try to use the filter function on my data_set like this:

songs %>% 
  filter(name == "RAP DEVIL", artists == "Machine Gun Kelly")

The output is just like this:

# A tibble: 0 × 18
# … with 18 variables: acousticness <dbl>, artists <chr>, danceability <dbl>, duration_ms <dbl>, energy <dbl>, explicit <dbl>,
#   instrumentalness <dbl>, key <dbl>, liveness <dbl>, loudness <dbl>, mode <dbl>, name <chr>, popularity <dbl>,
#   speechiness <dbl>, tempo <dbl>, valence <dbl>, year <dbl>, cluster <int>
# ℹ Use `colnames()` to see all variable names

can anybody help me what i did wrong. Thanks

Are you able to share the songs dataset? It's hard to troubleshoot without it.

1 Like

Sure! Here is the data set

I see the first artist is ['Carl Woitschach']

Try

filter(name == "RapDevil", artists == "['Machine Gun Kelly']")

1 Like

Thank you so much! I really thought that I should not include the ['..'] hahaha my mistake.

It looks like this would work.

filter(name == 'RAP DEVIL', str_detect(artists, 'Machine Gun Kelly'))
1 Like

It also worked thanks so much!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.