0

library(tidyr) library(dplyr)

df<-data.frame(Col=c("1::F::1::10::48067","2::M::56::16::70072","3::M::25::15::55117"))


df%>%separate(df,c("Sr No.","Gender","Occupation","Age",,"Zip-code"),"::")

Error Message:

Error in if (!after) c(values, x) else if (after >= lengx) c(x, values) else c(x[1L:after],  : 
  argument is of length zero
zx8754
  • 52,746
  • 12
  • 114
  • 209
  • Please show a small reproducible example and expected output – akrun Jan 24 '18 at 11:27
  • something like this before <- data.frame( attr = c(1, 30 ,4 ,6 ), type = c('foo_and_bar', 'foo_and_bar_2') ) before %>% separate(type, c("foo", "bar"), "_and_") – mihir deshpande Jan 24 '18 at 11:29
  • Did you meant `before %>% separate(type, c("foo", "bar"), sep="_and_")` which works for me – akrun Jan 24 '18 at 11:31
  • have a look at the image uploaded..This works for me too,I am trying to do it on an actual dataset and it is throwing an error.Have a look at the screenshot of the first 10 rows of that dataset(link in the question),The columns are" Sr No.","Gender","Age","Occupation","Zip-code" appearing in one column separated by :: – mihir deshpande Jan 24 '18 at 11:35
  • @mihirdeshpande then please provide an example data that would throw the same error. – zx8754 Jan 24 '18 at 11:36
  • @zx8754 have a look at the edit – mihir deshpande Jan 24 '18 at 11:52
  • 1
    The correct syntax for `separate()` includes both the data frame and column to be separated, so `df%>%separate(.,Col,c("Sr No.","Gender","Age","Occupation","Zip-code"),"::")` works correctly. – Len Greski Jan 24 '18 at 11:58

0 Answers0