R the mean of each iteration of the for loop

daisydomnie

My code:

V_max=15
H=1
n=1
C=c(0,0.01,0.1,1)



fun <- function( C, H, n ){
  2 / (3 + (C / H)^n) 
}


for(i in 1:length(C)){
V_C <- V_max*fun(C[i],H,n)
x3 <- rnorm(1000,V_C,1)

}

I want my loop to iterate over all the values of vector C and calculate the means for each iteration successively and that the means are save as one data.frame. Since these are my beginnings in R, I am asking for help

Ju Ko

You already got the right clue from Paul Stafford Allan but since you siad you are new to R, I included his tip in your original code:

V_max=15
H=1
n=1
C=c(0,0.01,0.1,1)



fun <- function( C, H, n ){
  2 / (3 + (C / H)^n) 
}

# generating empty vector
means_vec <- vector()

for(i in 1:length(C)){
  V_C <- V_max*fun(C[i],H,n)
  x3 <- rnorm(1000,V_C,1)
  
  # saving value in empty vector in each iteration
  means_vec[i] <- mean(V_C)
  
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Random Iteration Loop in R

From Dev

Saving slope of each iteration from a loop in R

From Dev

How to wrap each iteration in $each loop?

From Dev

mean for different variables in each iteration

From Dev

How to include jade template with each iteration in a loop?

From Dev

Next iteration in `each` loop

From Dev

How to print concatenated string a result of each for loop iteration in R

From Dev

Uninitialized integer not resetting in each iteration of the loop

From Dev

R print confusion matrix in each iteration within for loop

From Dev

How to create new variable at the end of each loop iteration in R

From Dev

Delaying For Loop Between Each Iteration

From Dev

How to loop through the columns in an R data frame and create a new data frame using the column name in each iteration?

From Dev

R: Loop a command to solve for a numeric variable that increases in each iteration until sum converges to a given integer

From Dev

How to change variable name with each iteration of a loop?

From Dev

How to return multiple values from a function in R for each iteration of a loop? Simple life history simulation

From Dev

Is there a way in R to store each iteration of a loop into a separate variable?

From Dev

Storing loop output in a dataframe in R for each iteration

From Dev

Readline on each iteration in for loop javascript

From Dev

output from print() replacing itself on each iteration of a loop in R

From Dev

How to create new dataframes for each iteration in R for loop?

From Dev

Force R to write loop output to list after each iteration

From Dev

R: Get the mean for each column with the loop for

From Dev

Caching data in each iteration of a for loop

From Dev

R Loop to calculate mean for each of two variables

From Dev

How to make loop with features selection by features importance where deleted features with imp = 0 or below mean imp in each iteration in Python?

From Dev

Drop borrow in each loop iteration

From Dev

Saving the output of each iteration of a for loop into a different df in r

From Dev

How to save the results of each for-loop iteration in a dataframe in R

From Dev

R: Save Each For-Loop Iteration As New Named List inside List

Related Related

  1. 1

    Random Iteration Loop in R

  2. 2

    Saving slope of each iteration from a loop in R

  3. 3

    How to wrap each iteration in $each loop?

  4. 4

    mean for different variables in each iteration

  5. 5

    How to include jade template with each iteration in a loop?

  6. 6

    Next iteration in `each` loop

  7. 7

    How to print concatenated string a result of each for loop iteration in R

  8. 8

    Uninitialized integer not resetting in each iteration of the loop

  9. 9

    R print confusion matrix in each iteration within for loop

  10. 10

    How to create new variable at the end of each loop iteration in R

  11. 11

    Delaying For Loop Between Each Iteration

  12. 12

    How to loop through the columns in an R data frame and create a new data frame using the column name in each iteration?

  13. 13

    R: Loop a command to solve for a numeric variable that increases in each iteration until sum converges to a given integer

  14. 14

    How to change variable name with each iteration of a loop?

  15. 15

    How to return multiple values from a function in R for each iteration of a loop? Simple life history simulation

  16. 16

    Is there a way in R to store each iteration of a loop into a separate variable?

  17. 17

    Storing loop output in a dataframe in R for each iteration

  18. 18

    Readline on each iteration in for loop javascript

  19. 19

    output from print() replacing itself on each iteration of a loop in R

  20. 20

    How to create new dataframes for each iteration in R for loop?

  21. 21

    Force R to write loop output to list after each iteration

  22. 22

    R: Get the mean for each column with the loop for

  23. 23

    Caching data in each iteration of a for loop

  24. 24

    R Loop to calculate mean for each of two variables

  25. 25

    How to make loop with features selection by features importance where deleted features with imp = 0 or below mean imp in each iteration in Python?

  26. 26

    Drop borrow in each loop iteration

  27. 27

    Saving the output of each iteration of a for loop into a different df in r

  28. 28

    How to save the results of each for-loop iteration in a dataframe in R

  29. 29

    R: Save Each For-Loop Iteration As New Named List inside List

HotTag

Archive