How to plot based on a wildcard

1817 views r
3

I have data that looks like this:

A 2 3 LOGIC:A
B 3  3 LOGIC:B
C 2 2 COMBO:A

plot(Data$V2[Data$V4 == "LOGIC:A"], DATA$V3[Data$V4 == "LOGIC:A"])

However I want to plot whenever the column 4 is LOGIC, when I provide "LOGIC" inside the plot command it should plot both "LOGIC:A" and "LOGIC:B". Right now it only accepts the exact column 4 value. Can I use wildcards?

answered question

1 Answer

8

You can use grepl to find occurrences of your string.

x <- c("LOGIC: A", "COMBO: B")
x[grepl("LOGIC", x)]
[1] "LOGIC: A"

posted this

Have an answer?

JD

Please login first before posting an answer.