-1

in want to split the "gender.age" column to two new columns "gender" and "age"

enter image description here

Roman
  • 15,874
  • 2
  • 28
  • 44
  • 1
    Welcome to Stack Overflow. Please read the help pages(https://stackoverflow.com/help), take the SO tour (https://stackoverflow.com/tour), read about how to ask good questions (https://stackoverflow.com/help/how-to-ask), as well as this question checklist (https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please learn how to create a Minimal, Complete, and Verifiable Example (https://stackoverflow.com/help/mcve). – Cettt Apr 29 '19 at 13:59
  • don't use pictures of your data, paste `dput(head(your_data, 10))` into the question. Please check `tidyverse` and the function `seperate`. – Roman Apr 29 '19 at 13:59

1 Answers1

1

Using tidyverse

library(tidyverse)
df <- tibble(
    gender.age = c("f 46",
                   "f 40",
                   "f 55",
                   "m 52",
                   "f 58",
                   "m 57",
                   "m 27",
                   "m 39")
)

df_2 <- df %>%
    separate("gender.age",
             into = c("gender", "age"),sep = " ")

df_2
Henry Cyranka
  • 2,783
  • 1
  • 14
  • 20