R programming language

First of all I want to clarify once again (I already have asked here a couple of pretty basic questions) that I am new at learning R, so my level is pretty low.

I am now learning about creating empty objects so you can assign a value for each element later.

The thing is I don’t quite understand the concept of level and label when creating a factor. For what I understood, I wanted to create a factor with the levels “s” and “n”, but that the label for the level was “sí”, “no”. But it is not working so I don’t know if I am doing it wrong or if I am not understanding how this works. I asked chatgpt but it broke, keeps telling me that I am doing it wrong and that’s why it doesn’t work yet when it shows me the “right” code, it is literally the same thing I wrote, I still try it because idk but surprise, it shows the same error. After 10 minutes trying to tell chatgpt that it is not right, I gave up and decided to come here instead.

So, the code I wrote is:

> patata <- factor(levels=c("n","s"), labels=c("No","Sí"))

> patata[1] <- "s"

And it gives me this error:

Warning message:

In '<-.factor'('tmp', 1, value = "s") :

invalid factor level, NA generated