Learner Learner - 1 year ago 46
R Question

Column name not found even it exists in a matrix

I'm trying to subset my data based on a condition but I'm getting the following error

> colnames(m)
[1] "Total"
> a <- subset(m,Total>1000)
Error in subset.matrix(m, Total>1000) : object 'Total' not found


Am I overlooking something here? Thanks

Answer Source

You can use subset like:

m[subset(m, select = "Total") > 1000, ]