Aspiring Developer
Aspiring Developer

Reputation: 680

Comparing Character Vectors Per Row in R if Same True/False

I'm missing something very simple here.

I tried referring to This Post

I'm trying to compare 2 character vectors to see if they equal each other on a per row basis, just expecting a TRUE / FALSE result per row. (Trying to find the FALSE)

all(data.frame(dBase$process_name == dBase$import_process))

When I run the above I receive the result:

Error in FUN(X[[i]], ...) : only defined on a data frame with all numeric variables

I tried this as well but it seems to be overall, not per row.

identical(dBase$process_name, dBase$import_process)

So is there an alternative to comparing characters / strings to see if they are the same and pull up the rows were FALSE occurs?

Upvotes: 2

Views: 1045

Answers (1)

ogroendal
ogroendal

Reputation: 353

If dBase is the name of an existing data.frame, then you can do the following to see all the rows where process_name and import_process are not identical. Notice that I use the != to get only those where they are not equal.

dBase[ dBase$process_name != dBase$import_process, ]

Upvotes: 1

Related Questions