I have an dataframe that I've read from a CSV that I'm trying to clean up. This is what it looks like:
A B C
1 0 X;Y;Z true
2 2 Y;Z false
3 5 X:Y false
What I'm trying to break up is the B column into a binary input like this:
A B C has.x has.y has.z
1 0 X;Y;Z true 1 1 1
2 2 Y false 0 1 0
3 5 X:Y false 1 1 0
I tried using an ifelse with an assignment but it applies the value to the whole column. How do I break it down to apply to reach row individually?
raw <- read.csv("data.csv")
raw$has.x <- ifelse("x" %in% raw[,"B"], 1, 0)