@Cath I've got a real quarantine beard. I'm staying at home with the kids, so it's been a good excuse to just do a tidy trim and let it grow out rather than a close trim suitable for an office.
To clarify about the label order, do you mean, for example, that row 2 of column V1 could be "__label__2" and V3 could be "__label__1" while row 1 could be in the reverse order?
That's strange that you get a data.frame from the output of system. I'm following the code you've posted in your question and I get a character vector.
What I had in mind with fread would be something like: library(data.table); fread(cmd = "fasttext predict-prob model_data.bin data.test.txt 2"). Looking at the resulting string in your sample data, you'd end up with a 4-column data.table. I don't know enough about the fasttext format to say whether this is a good answer or not. For instance, will there always be the same number of labels per element of res? Will the labels always be the same?
For instance, with the reprex you've shared, the following would work: x <- fread(cmd = "fasttext predict-prob model_data.bin data.test.txt 2"); ind <- rep(c(FALSE, TRUE), length.out = ncol(x)); x <- setnames(x[, ..ind], sapply(x[, !ind, with = FALSE], [[, 1))[]; x but I'm not sure whether that solution generalizes to the fasttext data structure in general. Hope this helps!
fread (from data.table) should be able to read from system commands. If you dput the head of the data you managed to read in using system and show your desired output, it would be easier to help out.
OK. You'll get much faster help here on Stackoverflow if you share reproducible examples like I've done here in the chat. That's what most of the people answering questions expect.
> y <- data.frame(id = c("a", "b", "c", "d"), choice = c("this,that,those", "that,those", "this,those", "this,that,those,these"))
> y
id choice
1 a this,that,those
2 b that,those
3 c this,those
4 d this,that,those,these
@Pre, one way would be to do something like (!is.na(x[cols_of_interest]))+0 (where cols_of_interest would be the columns you want to convert to binary.
@Pre, What would be an example of a 2-way frequency table's input and output from your data? The "questionr" package also has a cross.multi.table function that you might want to look at.