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

drlucyasher lasher at rvc.ac.uk
Wed Sep 9 18:40:58 CEST 2009


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.




More information about the R-help mailing list