1

I am a beginner to R. I have 13 variables to combine into 1 variable.

I want to override the combined cell if an unrelated VariableX = a specific string, if so, the corresponding cell of the new variable should = the string.

I tried to do this together with an ifelse statement, but didn't really work:

Sectors <- paste0("sector", 1:13)
Combinedsectors <- combinedlocations %>% ifelse (Type.of.org != "Independent 
Artist", 
unite(Sector, Sectors, na.rm=TRUE, remove=TRUE), $Sector="Independent 
Artist")

What I've done now is combine the sectors into one variable - is it better to just change that call after combining? If so, what would be the code for that?

This is the code I tried to use after first merging the columns:

combinedlocations$Sector = ifelse(combinedlocations$Type.Of.org="Independent 
Artist" & !is.na(combinedlocations$Type.Of.org), "Independent Artist", 
combinedlocations$Sector)

It gave me an error: Error: unexpected '=' in "combinedlocations$Sector = ifelse(combinedlocations$Type.Of.org="

Pre
  • 111
  • 7
  • If you want to check for equality you need to use a doube equal sign: `==`, so it should be `ifelse(..... == "Independent Artist" ...)` – deschen Nov 16 '20 at 22:50
  • thanks!! I figured this out - I used this method: https://stackoverflow.com/questions/54615462/how-to-replace-certain-values-in-a-specific-rows-and-columns-with-na-in-r – Pre Nov 17 '20 at 00:32

0 Answers0