Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple separate arguments in 'tidyr's separate function

Tags:

r

dplyr

tidyr

I have an issue about separation of one column into multiple columns.

The string example I want to separate is something like '87 BestMovie.GOOD' separate locations are space ' ' and '.'

I tried like this

df=data.frame(Eastwood=c('87 BestMovie.GOOD'))
sep=df%>%
separate(Eastwood,into=c('age','Select','Movie'),sep=c(' ','.'))

Warning messages: 1: Too many values at 1 locations: 2 2: Too few values at 1 locations: 1

or for another perspective, can we implement string locations for separation?

Thanks!

like image 325
Alexander Avatar asked Mar 31 '17 00:03

Alexander


1 Answers

"sep" needs to be a single character value representing a regular expression. Do this:

df %>% separate(Eastwood,into=c('age','Select','Movie'),sep=" |\\\\.")
like image 187
thc Avatar answered Oct 14 '22 13:10

thc