if a variable is superior to a value, add it to a vector in r

To check if a variable is greater than a value and add it to a vector in R, you can use a conditional statement and the append() function.

Suppose you have a variable x and a vector my_vector, and you want to add x to my_vector if it's greater than or equal to a value y. Here's an example code:

main.r
x <- 10
y <- 5
my_vector <- c(1, 2, 3)

if (x >= y) {
  my_vector <- append(my_vector, x)
}
92 chars
8 lines

In this code, the if statement checks if x is greater than or equal to y. If it's true, the append() function adds x to the end of my_vector.

After running this code, my_vector will be updated to include x:

main.r
> my_vector
[1] 1 2 3 10
25 chars
3 lines

gistlibby LogSnag