Vectors as feature for training in caret, R

I'm learning machine learning through using the R package caret, which have a lot of nice tools, however I wonder if I have a vector(or matrix) of numerical values as a feature for each predictor row.

Is there a neat way of getting this in the dataframe?

Or will I have to explicitly make columns for each index?

If not, does caret(or similar) packages support list data or lists of lists as input? eg.

x <- list(c("a","b","c"), c(TRUE, FALSE, TRUE), list(c(1,2,3), c(3,4,5),c(5,6,7))

Answer to suggestion from comments: Suggestion returns:

   V1  V2    V3 V4 V5
1  a  TRUE   1  3  5
2  b  FALSE  2  4  6
3  c  TRUE   3  5  7

I'd like something like:

   V1 V2     V3 
1  a  TRUE   (1, 2, 3)
2  b  FALSE  (3, 4, 5)
3  c  TRUE   (5, 6, 7)

Upvotes: 0

Views: 186

Answers (1)

DunderChief
DunderChief

Reputation: 726

As long as the vectors are of equal length, you may have each element of your vector as a separate column.

data.frame(V1=c("a","b","c"), 
           V2=c(TRUE, FALSE, TRUE), 
           V3=c(1,3,5), 
           V4=c(2,4,6), 
           V5=c(3,5,7)))

Upvotes: 1

Related Questions