2

I am working on a dataset, where I am doing feature engineering

dataset $ variable1 [dataset $ variable2 == "A"] = "B"

Where I am trying to convert variable1 to B, wherever variable2 is A. But instead of this, my output is showing a warning and it is making all tha values of variable1 as NA (pertaining to variable2 being A), instead of B

Where am I going wrong?

user11281949
  • 105
  • 6
  • 1
    Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Apr 07 '19 at 04:38

1 Answers1

1

I tried creating a sample of your described scenario. What is your data schema?

test1=data.frame(var1=c("a","b","a","a","b","a"),var2=c("a","b","a","b","a","b"),stringsAsFactors = FALSE)

test1$var1[test1$var2=="a"]="b"

Did not get the error. I dont have the reputation to comment. Can you describe what is the error message? I will edit my response based on your input.

Swati Singh
  • 100
  • 5