0

I'm trying to add those data with each other, but I found "N/A" in the final output when I enter new names didn't exists in the first vector, so how can i handle it to show all the data without any "N/A"

enter image description here

Mahmoud Badr
  • 303
  • 1
  • 11
  • We need to add "Maori" to party_fac. Something like: `party_fac <- c(party_fac, "Maori")`. Provide example data please. – zx8754 Feb 01 '22 at 08:05
  • Please don’t use images of data as they cannot be used without a lot of unnecessary effort. [For multiple reasons](//meta.stackoverflow.com/q/285551) Questions should be reproducible. Check out stack overflow guidance [mre] and [ask]. Include a minimal dataset in the form of an object for example if a data frame as `df <- data.frame(…)` where … are your variables and values or use `dput(head(df))`. [Good overview on asking questions](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Peter Feb 01 '22 at 09:17

1 Answers1

0

I think you just want to merge/append two factors, an easy approach would be to convert them to character, append them and make it a factor again.

Just a simple example with letters

p <- as.factor(LETTERS[3:8])
q <- as.factor(LETTERS[1:5])

as.factor(c(as.character(p), as.character(q)))

#  [1] C D E F G H A B C D E
# Levels: A B C D E F G H
Merijn van Tilborg
  • 5,452
  • 1
  • 7
  • 22