r - Extract Characters/String before Space from a factor data type column -
this question has answer here:
- remove after space in string in r 3 answers
i have r data frame in 1 column has factor data type text in column. want extract string column considering text before space. tried gsub( " .*$", "", data[, 3] )
,where summary field.but not working. example: data "abcd efgh ijk" & want "abcd"
tried convert factor field character field using
data[, 3] <- sapply(data[, 3], as.character)
but it's failed retrieve string before first space. can please help?
sorry can't able put data here client data
or
x <- "abcd efgh ijk" strsplit(x, " ")[[1]][1]
Comments
Post a Comment