[R] hist function in a for loop

Rui Barradas ruipbarradas at sapo.pt
Tue Jun 18 18:57:32 CEST 2013


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.
>>
>> ______________________________________________
>> R-help at r-project.org 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.
>>



More information about the R-help mailing list