0

I have a data set called Data_T_2Partner that has a column titled "Order" which contains strings. I want to filter out rows in which the comments entry contains the word OTW

I read the data into R from an xlsx file. I have tried this function:

Data_T_2Partner <- Data_T_2Partner %>%
filter("OTW", Order Channel Code)

However, I get an error that says:

Error: unexpected symbol in:
"Data_T_2Partner <- Data_T_2Partner %>%
filter("OTW", Order)

#   Item   Item description Order
#    1         Mocha            OTW
#    2         Venti            MOP
#    3         Blonde           OTW
#    4         Iced             CAFE
Away-Zone
  • 1
  • 2
  • It would be much better if you could share a reproducible piece of your data, so that others can help you more efficiently. – Anoushiravan R Apr 13 '21 at 23:13
  • What is the name of the column you would like to put a filter on? – Anoushiravan R Apr 13 '21 at 23:19
  • I added some sample data. Sorry i am new to stack overflow. I want to filter the column Order – Away-Zone Apr 13 '21 at 23:42
  • 1
    No it's ok. Just whenever you would like to ask a question bear in mind to share a reproducible piece of your data with this code : `dput(head(my_data_frame))` it will create a reproducible data frame so that others can use it. – Anoushiravan R Apr 14 '21 at 00:04

2 Answers2

1

If you would like refer to your new column name, you have to surround it with back ticks. That's because this naming is against R's naming conventions. So I think you can use the following code for filtering:

library(dplyr)

Data_T_2Partner <- Data_T_2Partner %>%
filter(`Order Channel Code` == "OTW")

I assumed that you already changed your column name to this.

Anoushiravan R
  • 21,622
  • 3
  • 18
  • 41
0
Data_T_2Partner <- Data_T_2Partner %>%
    filter(Order == "OTW")
crestor
  • 1,388
  • 8
  • 21