To find the maximum element in every 10 element window of a list in R, you can use a loop and the max()
function. Here's an example:
main.r454 chars17 lines
In this example, we first create a list with 100 random integer elements. We then create an empty vector called max_values
to store the maximum values we find. Next, we use a loop to iterate over every 10 element window in the list.
Within the loop, we use the max()
function to find the maximum value in the current window, and then add that maximum value to our max_values
vector using the c()
function.
After the loop is finished, we print out the max_values
vector to see the maximum value in every 10 element window.
gistlibby LogSnag