lundi 2 mars 2020

How to get result for a condition in a single line in r

I have a piece of code where I have to filter a dataframe based on a value. I read a dataset with 100 rows of data.

baseData = fread(file = "./Data/ABC.csv", data.table = FALSE, stringsAsFactors = FALSE, showProgress = FALSE, encoding = "UTF-8")

After I filter,

baseData = baseData %>% filter(., ab == 10)

Now I want to check whether the data has been filtered correctly. So I have written a condition,

ifelse((baseData$ab == 10),
       "ab has been filtered correctly",
       "ERROR")

but I have received the output like this,

[1] "ab has been filtered correctly" "ab has been filtered correctly" "ab has been filtered correctly"
[4] "ab has been filtered correctly" "ab has been filtered correctly" "ab has been filtered correctly"
[7] "ab has been filtered correctly" "ab has been filtered correctly" "ab has been filtered correctly"
[10] "ab has been filtered correctly" "ab has been filtered correctly" "ab has been filtered correctly"
.
.
.

I need a output like this,

"ab has been filtered correctly"

If possible along with the count of how many errors?

Aucun commentaire:

Enregistrer un commentaire