If I understand it correctly, you can just take a subset of iris using the results from cutoff.k
, since that returns a vector with the names of the variables you want to keep:
newdata <- iris[,cutoff.k(weights, 2)]
Here the []
command is used to get a subset of iris, in this case only the columns with the names in the result from cutoff.k
(rows/columns are indicated as follows: [rows,columns]
) .
To get a matrix
instead of a data.frame
: as.matrix(iris[,cutoff.k(weights, 2)])