[R] Help with Identify the number (Count) of values that are less than 5 char and replace with 99999

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Mon Dec 16 14:55:53 CET 2019


On Mon, 16 Dec 2019 13:24:36 +0000
Bill Poling <Bill.Poling using zelis.com> wrote:

> Using the nchar function (I converted the Factor to a character
> column first) I get the first 1K values.

<...>

> 1. Identify the number (Count) of values that are less than 5 char
> (i.e. 2 char = 150, 3 char = 925, 4 char = 1002)

Use the table() function to get frequency counts for discrete-valued
data (like nchar()).

> 2. Replace with 99999 as well as replace the NA's with 99999

An expression like `nchar(x) < 5` returns a boolean vector with TRUE
where the condition is, well, true, and FALSE otherwise. Use this vector
together with the subset operator (square brackets []) and assignment
operator (<-) to perform a subassignment of "99999" to the elements
of your dataset where the condition is true:

https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Index-vectors

See also: ?`[` and ?table

-- 
Best regards,
Ivan



More information about the R-help mailing list