I was following along to this post here to figure out how to change my factor into a numeric value in R Studio. The factor in question does have NA's which I put in there myself. I need to use this factor in a tapply()
code later and want to make sure that the NA's won't be a problem.
Example Code:
factor.1[2] <-NA
factor.1[7] <-NA
factor.1[12] <-NA
Then, following the directions on the linked post:
num.fact1 <- as.numeric(levels(factor.1))[factor.1]
The "error" I get is "NA's introduced by coercion". But it does let me proceed, regardless. Now, tapply:
tapply(
num.fact1,
factor.2,
mean, na.rm=TRUE
)
I think the output looks fine/accurate. I want to make sure that the error I have with "NA's introduced by coercion" won't be a problem, especially when I knit this notebook to PDF.