I am relatively new to R programming. I am writing a code that generates an array of numbers:
[1] 0.5077399, 0.4388107, 0.3858783, 0.3462711, 0.3170844, 0.2954411, 0.2789464, 0.2658839,
[9] 0.2551246, 0.2459498
Note: I manually separated the values by commas for ease on the eyes :)
I want to pick the first 3 numbers from this array that are below 0.3 - [0.2954411, 0.2658839, 0.2551246]
. In addition to picking these values, I want to generate the numbers that represents where those three values exist within the array. In this case, I want the code to give me [6,7,8].
How would I write code to do this?
I greatly appreciate the help.
For a similar simulated set,
y <- c(2, 4,6, 8)
ind <- which(y < 6) ## for finding indices 1 and 2
val <- y[y<6] ## for picking values 2 and 4
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments