zlee11
zlee11

Reputation: 69

Set maximum and minimum values for matrix in R

I have a n x 3 matrix. My column headings are longitude, latitude, and energy value.

I am trying to set an upper and limit for my 3rd column ('energy value' column) only. How do I ensure only values between 1 and 90,000 remain in that column?

Thanks!

Upvotes: 0

Views: 452

Answers (3)

akrun
akrun

Reputation: 887213

We could also do

library(dplyr)
m %>%
    as.data.frame %>%
    filter(between(V3, 1, 90000))

Upvotes: 0

ThomasIsCoding
ThomasIsCoding

Reputation: 101663

Other options in addition to the answer by @Edo

subset(m, data.table::between(m[,3],1,90000))

or

subset(m, m[,3] >= 1 & m[,3] <= 90000)

Upvotes: 1

Edo
Edo

Reputation: 7818

assuming m is your matrix:

m[m[,3] >= 1 & m[,3] <= 90000, ]

Upvotes: 2

Related Questions