[R] R code for creating and appending to frequency table

jim holtman jholtman at gmail.com
Wed Sep 9 20:01:50 CEST 2009


If the result of the 'table' is a different length each time, then you
will have to consider the use of a list.  If it is the same length,
then something like this should work

results <- matrix(ncol=50, nr=10)
for (i in 1:50) results[,i] <- your computation for table

On Wed, Sep 9, 2009 at 12:40 PM, drlucyasher<lasher at rvc.ac.uk> wrote:
>
> Apologies for what might seem like an simple question.
>
> I have written a model which gives me a frequency distribution for a
> particular score within a set. What I now want to do is loop this so that I
> get many different frequency distributions and append them to a table with a
> collum which specifies which loop the frequency distribution is from. What I
> wantto end up with would look something like this:
>
>     Score
>     1  2  3  4  5
> 1   5  6  7  4  1
> 2   2  5  8  1  1
> 3   3  8  9  2  1
> 4   etc
> 5
> .
>
> Without the loop I can get the model to report the frequency distributions
> using the c(table()) command.
>
> SO then I added the loop. I added a command to specify that this object fdt
> was controlled by time (t). My original object which calculates the freq
> distribution for a single loop is fd
>
> t<- 50 #number of simulations
> fdt<- numeric (t)#define terms affected by time
> for (l in 1:t) #loop start stop
>
> and then at the end of the loop have tried various commands:
>
> e.g.
> fdt[l]<- c(table(fd))
> fdt[l] <- fd       c(table(fdt))
> c(table(fdt[l]))<- fd
>  c(table(fdt[l]))<- c(table(fd))
> and some other commands using append and assign.
>
> None of these produces what I am looking for and some mess up the rest of my
> caculations. When I tried the second of these I get the warning Warning:
> number of items to replace is not a multiple of replacement length.
>
> Any help would be much appreciated.
>
> --
> View this message in context: http://www.nabble.com/R-code-for-creating-and-appending-to-frequency-table-tp25368860p25368860.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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list