building an R loop for random sampling

I am sampling from a file containing a list of many values eg:

312313.34
243444
12334.92
321312
353532

and using R to randomly sample from this list:

list = read.table("data")
out <-sample(list,50,replace=TRUE)
out.mean<-mean(out)
out.mean

Could somebody please show me how to put this into a loop, so that I can perform this procedure 1000 times and take the mean of the 1000 means that this will generate?

Thank you very much in advance!

Rubal

Answers


An alternative solution could be (keep in mind what @Tyler Rinker just said about replicate)

Data <- read.table(text='
312313.34
243444
12334.92
321312
353532', header=FALSE)

Data <- as.numeric(as.matrix((Data))) 

set.seed(007)
Means <- replicate(1000, mean(sample(Data,50,replace=TRUE))) 

Means consists of 1000 mean each one for every subsample of size 50. If you want the mean of the means do this:

mean(Means) 

What you're trying to do sounds like a bootstrapping or something similar to resample techniques for bias reduction (I guess).


Need Your Help

Cannot select javascript populated form options in IOS

javascript html ios forms

I have created a website for an estate agent and there is a search form on the left hand side of the page which is partially populated by javascript depending on whether the viewer wants to rent or...

Julia uninitialize array at particular index

arrays julia-lang

I'm writing a neural network in Julia that tests random topologies. I've left all indices in an array of nodes that are not occupied by a node (but which may be under a future topology) undefined a...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.