Learner Learner - 6 months ago 27
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


You can use subset like:

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