find the smallest element in an array in r

To find the smallest element in an array in R, you can use the min() function. Here's an example:

main.r
# Create an example array
my_array <- c(5, 10, 2, 8, 1)

# Find the smallest element in the array
smallest_element <- min(my_array)

# Print the result
print(smallest_element)
176 chars
9 lines

Output:

main.r
[1] 1
6 chars
2 lines

In this example, the min() function is used to find the smallest element in the my_array array. The result is then printed to the console.

related categories

gistlibby LogSnag