Assign a factor level when constraints are met in R -


i think i'm half way want doing using (just need little doing second part):

clients[which(clients$age >= 18 & clients$age <= 24),] 

this groups 18 years of age 24 years of age (inclusive) , lists rows match in data frame.

i want go 1 step further , assign every row matches constraint level of factor variable; 'i'. , 25 - 34 can part of 'ii', 35 - 44 part of 'iii', etc, etc.

the ultimate goal make easy me plot frequency different age groups next 1 - feel making them each unique levels in factor variable start.

any ideas?

you use cut specify multiple levels @ once:

cut( clients$age,      breaks = c( 18, 25, 35, 45 ),      include.lowest = true,      labels = c( "i", "ii", "iii" ) ) 

an example, using every integer between 18 , 45.

cut( seq.int( 18, 45, 1 ),      breaks = c( 18, 25, 35, 45 ),      include.lowest = true,      labels = c( "i", "ii", "iii" ) )  [1]                 ii  ii  ii  ii  ii  ii  ii  ii  ii  ii  iii iii iii iii [23] iii iii iii iii iii iii levels: ii iii 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -