# R: Parsing multiple values into a single field [closed]

I have multi-class classification dataset with data saved in the form.

[number, ..., number],number,number... ,number \n

The numbers inside brackets are the labels and have varying length. Numbers after are features with fixed length $n$. How to parse this into a R table?

There probably is some perfect way to load everything in one fell swoop but since it sounds like you need a quick-and-dirty solution, you could try something along the lines of:

library(stringi)

vals <- stri_split_coll(df$V2, pattern=',', simplify=TRUE, omit_empty = TRUE) vals <- data.frame(apply(vals, 2, as.numeric)) labels <- stri_replace(df$V1, '', fixed = '[')

[Note: If your data has a header then just add the argument "skip=1" to read.table and either add the columns manually or run the function again (with "nrows=1"), etc.]