Question

How can I convert this apply function in R studio apply(trees, 1, function(x) tree_s3(x[1],x[2],x[3])) into a...

How can I convert this apply function in R studio

apply(trees, 1, function(x) tree_s3(x[1],x[2],x[3]))

into a for loop?

Homework Answers

Answer #1

You can use for loop by iterating from 1 to the number of rows. Then access each row using the index as shown below.

We are iterating using rows because the margin argument is 1 in this apply statement.

Although I don't have the definition of what tree_s3( ) is doing so I cannot show you the exact output for this function. You can share the full code in the comments if you want me to show the exact conversion.

for i in 1:nrow(trees){

x <- trees[ i,  ]

#Your function here using x as the argument

}

(*Note: Please up-vote. If any doubt, please let me know in the comments)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How can I solve this exuation for x? r/(-b) = (x^2+a)/(x^2(x+a)^3)
How can I solve this exuation for x? r/(-b) = (x^2+a)/(x^2(x+a)^3)
In the R code (R studio), How to generate the gamma distribution by function?
In the R code (R studio), How to generate the gamma distribution by function?
In R- Studio : Write a function that takes as an input a positive integer and...
In R- Studio : Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Write a recursive function, do not use any of the loop commands in your code.
how to rename a row in r studio, for example view(mydata) a b c red 1...
how to rename a row in r studio, for example view(mydata) a b c red 1 4 yellow 2 4 white* 5 6 black 0 6 pink 6 3 purple 10 5 I want to rename the row 4, white* to white. I need to remove the "*" also I want to add a new column, with repetition values for ex. new column 1 2 3 1 2 3 please help, how can I write in R-program
Let f : R → R be a function satisfying |f(x) − f(y)| ≤ 3|x −...
Let f : R → R be a function satisfying |f(x) − f(y)| ≤ 3|x − y|^{1/2} for all x, y ∈ R. Apply E − δ definition to show that f is uniformly continuous in R.
By using the R-Studio answer the following question: 1. a) write a simple loop to list...
By using the R-Studio answer the following question: 1. a) write a simple loop to list the squares of the first 10 integers. b) Generate the 10*10 matrix A, whose (i;j) entry is sin(2*pi*(i-j))
Consider the function f(x,y) = -8x^2-8y^2+x+y Select all that apply: 1. The function has two critical...
Consider the function f(x,y) = -8x^2-8y^2+x+y Select all that apply: 1. The function has two critical points 2. The function has a saddle point 3. The function has a local maximum 4. The function has a local minimum 5. The function has one critical point *Please show your work so I can follow along*
Using the formual (2n-3)! / [2^n-2 x (n-2)!], how many possible rooted trees can you generate...
Using the formual (2n-3)! / [2^n-2 x (n-2)!], how many possible rooted trees can you generate using 6 organisma?
Using R or R-studio. 3. A fair coin is tossed until the first head occurs. Do...
Using R or R-studio. 3. A fair coin is tossed until the first head occurs. Do this experiment T = 10; 100; 1,000; 10,000 times in R, and plot the relative frequencies of this occurring at the ith toss, for suitable values of i. Compare this plot to the pmf that should govern such an experiment. Show that they converge as T increases. What is the expected number of tosses required? For each value of T, what is the sample...
How do I do this in R Studio   1. You are testing a hypothesis Ho: μ...
How do I do this in R Studio   1. You are testing a hypothesis Ho: μ = 10 against Ha: μ < 10 based on a SRS of 20 observations from a Normal population. The data give sample mean of 8 and a sample standard deviation of 4. Find the value of t. (use correct formula, plug numerical values into formula, crunch numbers using R, report value of t) 2. What is the area to the left of the t...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT