# 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?

## closed as off-topic by Nick Cox, Christoph Hanck, gung♦, Matt Krause, Juho KokkalaSep 30 '15 at 12:18

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Nick Cox, Christoph Hanck, gung, Matt Krause, Juho Kokkala
If this question can be reworded to fit the rules in the help center, please edit the question.

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.]