[R] Help with factor column replacement value issue-SOLVED

2018-11-16 Thread Bill Poling
Thanks again Michael, simple enough! r1z <- r1 str(r1z$B1) #Factor w/ 14 levels "Z","A","C","D",..: 2 2 3 3 2 2 2 2 2 2 ... # When you do your step of replacing lower case l with upper case L the # level still stays in the factor even though it is empty. If that is a nuisance r1z$B1 <- factor(r1z

Re: [R] Help with factor column replacement value issue

2018-11-16 Thread Bill Poling
Hi Jeff and Michael, thank you for your quick responses and suggestions I will try them out. Appreciate everyone's time! WHP My suggestion is to avoid converting the column to a factor until it is cleaned up the way you want it. There is also the forcats package, but I still prefer to work

Re: [R] Help with factor column replacement value issue

2018-11-16 Thread Bill Poling
Thank you Bert. WHP As usual, careful reading of the relevant Help page would resolve the confusion. from ?factor: "factor(x, exclude = NULL) applied to a factor without NAs is a no-operation unless there are unused levels: in that case, a factor with the reduced level set is returned. If excl

Re: [R] Help with factor column replacement value issue

2018-11-16 Thread Jeff Newmiller
My suggestion is to avoid converting the column to a factor until it is cleaned up the way you want it. There is also the forcats package, but I still prefer to work with character data for cleaning. The stringsAsFactors=FALSE argument to read.table and friends helps with this. On November 16,

Re: [R] Help with factor column replacement value issue

2018-11-16 Thread Michael Dewey
Dear Bill When you do your step of replacing lower case l with upper case L the level still stays in the factor even though it is empty. If that is a nuisance x <- factor(x) will drop the unused levels. There are other ways of doing this. Michael On 16/11/2018 15:38, Bill Poling wrote: Hel

Re: [R] Help with factor column replacement value issue

2018-11-16 Thread Bert Gunter
As usual, careful reading of the relevant Help page would resolve the confusion. from ?factor: "factor(x, exclude = NULL) applied to a factor without NAs is a no-operation unless there are unused levels: in that case, a factor with the reduced level set is returned. If exclude is used, since R ve

[R] Help with factor column replacement value issue

2018-11-16 Thread Bill Poling
Hello: I am running windows 10 -- R3.5.1 -- RStudio Version 1.1.456 I would like to know why when I replace a column value it still appears in subsequent routines: My example: r1$B1 is a Factor: It is created from the first character of a list of CPT codes, r1$CPT. head(r1$CPT, N= 25) [1] A4