• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home » Resolved: How to add both rows and columns to a for loop in R?

Resolved: How to add both rows and columns to a for loop in R?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I am trying to create a null bootstrap in R. The dataset has four species and associated sample values. I want to calculate the mean and a special poisson function, sampling 5 values at a time from the distribution associated with each species. Here is my attempt at the code. I sampled 5 and tried to use summarise to calculate the mean and poisson function from those five values. I get an error that says ! New rows can't add columns. Any suggestions on how to correct this to get the desrired output (attached).

Answer:

The issue with error is based on the difference in column name in ‘output’ i.e. poisson.set and in the for loop possion.set. By correcting either one of them, it works (In addition, sp was not created in the summarise resulting in NA)
In addition, we could do this without a for loop as well, i.e. group_by the ‘sp’ column and use replicate/rerun for multiple iterations

If you have better answer, please add a comment about this, thank you!

bootstrap-4 dplyr for-loop r
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How can I copy files using the ansible.builtin.copy module and avoid conflicting file names?

26/03/2023

Resolved: Reshape tensors of unknown shape with tf.function

26/03/2023

Resolved: Use Svelte Component as Slot

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.