r - Separate column into three columns with grouping -
this question has answer here:
i have column full names should separated 3 columns spaces. problem full names contains more 3 words, , 4-th , other words shouldn't omitted, added third part.
instance, "abdullaeva mehseti nuraddin kyzy" should separated as:
| abdullaeva | mehseti | nuraddin kyzy | i tried split column (tidyr) package follow, in way 3d part contains 1 word after second space.
df<-df %>% separate('full_name', c("1st_part","2d_part","3d_part"), sep=" ") any appreciated.
use extra argument:
# dummy data df1 <- data.frame(x = c( "some name1", "justonename", "some 3 name", "abdullaeva mehseti nuraddin kyzy")) library(tidyr) library(dplyr) df1 %>% separate(x, c("a1", "a2", "a3"), = "merge") # a1 a2 a3 # 1 name1 <na> # 2 justonename <na> <na> # 3 3 name # 4 abdullaeva mehseti nuraddin kyzy # warning message: # few values @ 2 locations: 1, 2 from manual:
extra
if sep character vector, controls happens when there many pieces. there 3 valid options:
- "warn" (the default): emit warning , drop values.
- "drop": drop values without warning.
- "merge": splits @ length(into) times
Comments
Post a Comment