I am trying to replace all values of a dataframe that have the word "coin" in it with 0, sample dataframe looks like this:
| P1 | P2 | P3 | P4 |
|---|---|---|---|
| 0 | 3 Coins | 2 | 1 |
| 2 | 4 | -2 Coins | 4 |
My first attempt was to just lapply(dataframe,function) using a function that conditionally checks if the value contains the string "coin" and then returns 0.
I'm sure there's more efficient ways to do this, but it's the best I could come up with as a beginner in R.
I am struggling with the grepl() function, which supposedly would return TRUE if the string contains the substring I am looking for. However, I am STRUGGLING to figure out why the following code is returning FALSE.
y = "-3 coins"
grepl(y,"coin",fixed=TRUE)
My question is: What am I doing wrong that this grepl is returning FALSE when "coin" is in the initial string, and is there a better way to achieve my end goal of replacing all cells that contain "coin" with 0?
Any help is very appreciated, thank you!!