1

I have a table like the following:

A, B, 
"Yes", 1
"Yes", 2
"No", 3

Is there any easy way to substitute all the cells with "Yes" for "Hello" instead so I get:

A, B, 
"Hello", 1
"Hello", 2
"No", 3
Alex
  • 627
  • 3
  • 12
  • 32

1 Answers1

1

We can use indexing (assuming the column 'A' is character class

df$A[df$A == 'Yes'] <- 'Hello'

Or with ifelse

df$A <- with(df, ifelse(A == 'Yes', 'Hello', A))
akrun
  • 874,273
  • 37
  • 540
  • 662
  • Pardon my ignorance, what is df$a? Edit: Nevermind, df is the name of the table and $A means the column A Thanks for your help! – Alex Dec 06 '20 at 23:30
  • @Alex I assume that the the data showed is a data.frame and here the object name is 'df' and the 'A' is the column name. We extract the columns as vector with `$` or `[[` or [` – akrun Dec 06 '20 at 23:33