Search code examples
rrstudio-server

I would like to group/split age values


I have a dataset that has the cat's ID number at a centre and their ages. The dataset looks like this:

ID Number   Animal Type          Age
 121012             Cat        0.002
 128129             Cat        1.000
 429202             Cat        0.920
 238232             Cat       15.000
 132265             Cat        0.050
 234235             Cat        9.000
 682892             Cat       16.000

A kitten has an age numerical value below 1, in other words, kittens can be any number that isn't a whole number. Meanwhile, adult cats have an age value that is any whole number.

I need to split the data, or better yet group, the kitten population from the adult population but I have no idea.

(Im still pretty new to this, only had it for 4 weeks so sorry if I sound like a noob)

Many thanks to anyone who can help!


Solution

  • In addition to the above answer, find below two more methods,

    Method 1

    df_kitten <- subset(df, Age <1)
    df_adult <- subset(df, Age >= 1)
    

    Method 2

    df_kitten <- df[df$Age < 1,]
    df_adult <- df[df$Age >= 1,]
    

    Thanks Balaji