[R] get information out of table() result

Sarah Goslee sarah.goslee at gmail.com
Wed Mar 16 14:10:48 CET 2011


table() returns a named vector. You need the names and the values.

Or you could read my reply to one of the OTHER appearances of this
email in my inbox; I think I've seen three, though I only replied to one
and now this. It truly is unnecessary to send your query several times in
quick succession, especially as many of the US potential respondents are
just getting to their computers. Using different email addresses just
makes us suspicious and less-inclined to be helpful.

If you don't receive a response in a day or so, then it's acceptable to ask
again, ideally with your further attempts to solve your own problem included.
Most messages that never receive replies were so badly stated that nobody
could figure out how to answer.

But since you've now gotten two replies, that shouldn't be necessary.

Sarah

PS Unless this is some sort of Nabble glitch resending your message multiple
times, in which case you should join the list the normal way.

On Wed, Mar 16, 2011 at 7:23 AM, fre <fre_stamlid at hotmail.com> wrote:
> I have the following problem:
>
> I have some string with numbers like k. I want to have a table like the
> function table() gives. However I am not able to call the first row, the 1,
> 2, 3, 5, 6 or 9. I tried to do that by a data.frame, but that doesn't seem
> to work either. The levels keep bothering me.
>
> This is an example of the code:
>
> k<-c(1,1,1,1,1,3,5,6,2,1,3,9,2,3,1,1,1)
>> table(k)
> k
> 1 2 3 5 6 9
> 9 2 3 1 1 1
>> x<-table(k)
>>
>> dim(x)
> [1] 6
>>
>> x[4] #But I only want to read the five
> 5
> 1
>>
>> x<-data.frame(x)
>>
>> x[4,1] #You are not allowed to use this five for example 3*x[4,1] is
>> impossible
> [1] 5
> Levels: 1 2 3 5 6 9
>>
>
> I hope anyone has an idea of using the table function without this
> inconvenience. I thought about writing a counter myself, but that seems
> complicated.
> Because I have to examine very large examples later on, I don't want to slow
> the calculations down if possible.
>
> Thanks for your help in advance.
>
> Frederique
>

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list