# hist function in a for loop

5 messages
Open this post in threaded view
|

## hist function in a for loop

 Dear all, I need to create a for-loop in which I can compute multiple histograms My code is the following : #singlefile includes huge csv file #I want to specify the binsize #I would like to compute in the for -loop the histograms     numfiles <- length(singlefile)     for (i in 1 :51)     {     binsize <- -20 :20/2     hist(singlefile(singlefile\$GVC[singlefile\$new_id==i]], break=seq(), by = binsize))) What do I have to do ? How can I specify the range for i  ? I am totally lost Thanks for support D.U Ms.Dizem Uerek
Open this post in threaded view
|

## Re: hist function in a for loop

 Hello, Sorry, I forgot to Cc the list. Rui Barradas Em 18-06-2013 16:29, Rui Barradas escreveu: > Hello, > > Inline. > > Em 18-06-2013 15:54, Dzu escreveu: >> Dear all, >> >> I need to create a for-loop in which I can compute multiple histograms >> My code is the following : >> #singlefile includes huge csv file >> #I want to specify the binsize >> #I would like to compute in the for -loop the histograms >> >> >>      numfiles <- length(singlefile) >>      for (i in 1 :51) >>      { >>      binsize <- -20 :20/2 >>      hist(singlefile(singlefile\$GVC[singlefile\$new_id==i]], >> break=seq(), by = >> binsize))) > > hist() does not have a 'by' argument. > Maybe what you want is something like the following. > > binsize <- -20:20/2 > h <- vector("list", 51) > for (i in 1:51) >      h[[i]] <- hist(singlefile\$GVC[singlefile\$new_id==i, ], > break=binsize, plot = FALSE) > > > This computes the histograms. Now to plot the histograms you use the > plot() function: > > plot(h[[1]])  # plots the first > > >> >> What do I have to do ? >> How can I specify the range for i  ? > > I don't understand. You want to match several values for i at once? > > singlefile\$GVC[singlefile\$new_id %in% irange, ] > > > Hope this helps, > > Rui Barradas >> >> I am totally lost >> Thanks for support >> D.U >> >> >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/hist-function-in-a-for-loop-tp4669797.html>> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> [hidden email] mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help>> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html>> and provide commented, minimal, self-contained, reproducible code. >> ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: hist function in a for loop

 Hello Thanks for reply I want to compute several histograms in a for loop.I am trying to set the binsize constant in the beginning. #compute the histograms  for (i in 1:12)     {     binsize <- -20 :20/2     hist(singlefile\$GVC(singlefile\$new_id[,i], freq = FALSE,xlab ="Graph i", col = "pink",main ="Example Histogram", ylim = c(-3.0,3.0)))     singlefile\$GVCmin <- min(singlefile\$GVC[1])     singlefile\$GVCmin <- min(singlefile\$GVC[1])     x1 <- seq(-3.0,3.0,by=.01)     lines(x1,dnorm(x1),col ="black")     } I tried also this but it does not do anything. I also tried your proposal , but it says that : breaks = binsize  is not allowed. I think I am totaly far away from that what I want to do with my code . One single histogram plotting and computing is easy , but if it is in the loop , by the syntax to feed the function with counter i is not working Thanks Dizem Ms.Dizem Uerek