I am new to r. I am trying to make my code less complicated by using a for loop

Sam Laski

Here is my current code... can I make this a for loop?

#sample1, sample2, …, sample6 where samplei is sampling 10^(ith)
sample1 <- abs(rnorm(10)) #use abs because bellcurve is + and -
sample2 <- abs(rnorm(10^2))
sample3 <- abs(rnorm(10^3))
  sample <- abs(rnorm(10^4))
  sample5 <- abs(rnorm(10^5))
  sample6 <- abs(rnorm(10^6))
Ventrilocus

If you also want to assign it to 6 different variables you will need to do:

n = 6
invisible(sapply(1:n, function(i) assign(x = paste("sample", i, sep = ""), 
                                         value = abs(rnorm(10^i)),
                                         envir = .GlobalEnv)))

Or with a for loop:

for(i in 1:n)
{
  assign(x = paste("sample", i, sep = ""), value = abs(rnorm(10^i)), envir = .GlobalEnv)
}

But it makes much more sense to store it as a list, like in:

samples = lapply(1:6, function(i) abs(rnorm(10^i)))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I am trying to make a loop that list square numbers. What is wrong with my Java code?

I am using DOS and I am trying to make the background white

I am trying to make my bot make a new channel with the name of a guild, if it has not already been made

I am trying to make this loop work, but I can't

I am trying to make my own Batch Game, but when I try to run the Script/Code it Instantly Closes

I am trying to export an excel and make it password protected. My code is given below.But i am getting error

Am I using the 'this' keyword properly in my code?

Is there a problem with my code or the API I am using?

I am trying to make my switch case loop back again if they get the user gets the default

I am trying to make a for loop but my computer is returning the following:Cannot read property 'length' of null

I am trying to make my php main class compress and use it like normal php code

i am trying to make a new component inside a js variable

I am trying to make a for loop with a if statement in it to find a specific name in an arraylist

I am trying to do a project on GTK+ using Glade but when I am compiling my code and running the executable file I am facing some errors

I am trying to make and ajax call to my django backend

I am trying to make two buttons for my main menu

I am trying to make this app bar this is my final goal

I am trying to make my regex work in MySQL but it's not working

I am trying to make custom errors if a path is not found in my server

I am new to javascript, and I am trying to make a html program to calculate dog age

I am trying to make a code editor, but nothing appears in the result box

I am trying to make this code work but failing due to End With

I am trying to make a tile layer be disabled in code Godot

I am trying to print escape characters using for loop. My motive is to see the values that gets printed

I am trying to filter some url from my fetch list by using for loop and if condition in python

I am trying to make an FPS soccer game using Unity, but my script isn't working

I am New To Flutter And I am In Bind with SetState Operation, I am Trying to Organize Code in a Block By Block way but setState is not working,

I am trying to know the reason my code is not running

I am new to C# and I am trying to study some sorting algorithm How do I make my selection sort accept negative numbers?