R for loop to display mean and max of each row in a matrix

71 views Asked by At

I am trying to create a for loop in R that will display the mean and max for each row in a matrix. Thus far I have:

for (i in 1:nrow(matrix_data)) {
   row_means[i] <- mean(matrix_data[i, ])
}
{
max_values_matrix_data [i] <- max(matrix_data [i, ])
}

Mean <- row_means
Max <- max_values_matrix_data

If I print Mean and Max I get a string of numbers (13 for each), but the assignment calls for the output to be formatted as:

Row: 1
Mean: 131.26
Max: 200

and so on for 13 rows.

0

There are 0 answers