[R] Summarizing levels for future commands
Suzanne E. Blatt
SuzieBlatt at netscape.net
Wed Apr 16 13:32:11 CEST 2003
Figured out one of my errors, forgot the 's' on the 'names' command. So, now I can get my max (or min) of the levels within my table and I can plug them successfully into my function farther along my code. However, how can I get the 2nd or 3rd most frequent level and use them as well as the most frequent level?
Thanks for the continued help,
Douglas Bates <bates at stat.wisc.edu> wrote:
>SuzieBlatt at netscape.net (Suzanne E. Blatt) writes:
>> Hi. This will hopefully be readily understood but if not, bear with me.
>> I have to do a repeated analysis (in spatstat) and want to batch file it. For each of my 'runs' certain variables change. At present I am manually specifying these changes and want to automate it if possible.
>> Ok, I am creating an object which is comprised of 'levels' that are 'characters'. Further in my program I need to select one of these 'levels' as the comparison to the others. The one I want to select is the most frequent and then compare it to the second most frequent. Is there anyway to get R to determine the most frequency of 'levels' in an object and then use a specific one in future functions? I couldn't find it in my search through the manual or the r-help archives.
>> I hope what I am attempting to do is clear, let me know if it isn't.
>I think I know what you want to do but I'm not sure. I believe you
>want to find the mode, or the "most popular" level. For example, in
>the following sample of size 50 from the values 1:10
>> samp = sample(1:10, 50, replace = TRUE)
> 1 2 3 4 5 6 7 8 9 10
> 5 3 7 3 4 2 8 9 3 6
>the most popular value is 8.
>As you can see, the table function tells you the frequencies of the
>values. From that it is just a matter of extracting the index of the
>value with the maximum count and getting the label.
>> names(tbl)[match(max(tbl), tbl)]
>Hope this helps.
More information about the R-help