Hi, for the specific example the issue is that the entire set of variables is read in as a single character variable. It looks like fixed width data, rather than comma or blank separated. If so, then you can specify the sep = argument as a numeric vector of positions to split at, so
separate(data = df, col = 1,
into = c("Instr Code", "Max Price", "Min Price", "Trades", "Quantity", "Value(In Mn)"),
sep = c(13,28,41,51,63),
convert = TRUE)
One drawback to this is that I think the "Instr Code" field will have trailing spaces.
Alternatively, and probably superior, you can use a simple regex (regular expression) to identify the
clumps of spaces in between the data fields.
separate(data = df, col = 1,
into = c("Instr Code", "Max Price", "Min Price", "Trades", "Quantity", "Value(In Mn)"),
sep = "\\s+",
convert = TRUE)
\s means any whitespace character, and + means one or more of the preceding character. The extra slash escapes the slash so R leaves it in the string before passing it to the regular expression. This will work unless the field "Instr Code" sometimes has spaces in it. Then you might be forced to use the numeric vector of positions.
If it was me, I would simplify the subsequent code by replacing the spaces in the variable names with _ or .. Also, you might be able to avoid this step by using readr::read_fwf() which would split things up by position as you were reading in the file.