[R] What is the difference between typeof and storage.mode?

David Winsemius dwinsemius at comcast.net
Thu Feb 11 03:44:14 CET 2010


On Feb 10, 2010, at 9:21 PM, bluesky315 at gmail.com wrote:

> On Wed, Feb 10, 2010 at 7:05 PM, David Winsemius <dwinsemius at comcast.net 
> > wrote:
>>
>> On Feb 10, 2010, at 7:54 PM, David Winsemius wrote:
>>
>>>
>>> On Feb 10, 2010, at 7:47 PM, bluesky315 at gmail.com wrote:
>>>
>>>> On Wed, Feb 10, 2010 at 6:40 PM, David Winsemius <dwinsemius at comcast.net 
>>>> >
>>>> wrote:
>>>>>
>>>>> On Feb 10, 2010, at 6:34 PM, bluesky315 at gmail.com wrote:
>>>>>
>>>>>> S Programming by Venables and Ripley (2000) says on page 8, "R  
>>>>>> objects
>>>>>> have another way to give information using the function
>>>>>> \tttext{typeof}, which often gives the same information as
>>>>>> \tttext{storage.mode}." It implies that there are some  
>>>>>> differences
>>>>>> between typeof and storage.mode.
>>>>>>
>>>>>> However, according to ?typeof and ?storage.mode, it doesn't  
>>>>>> seem to be
>>>>>> so. Could somebody let me know if there is any difference? If  
>>>>>> there
>>>>>> is, what the difference is?
>>>>>
>>>>> Dear Peng Yu;
>>>>>
>>>>> There is a difference.
>>>>
>>>> Would you please give me an example when they will be different?
>>>
>>> It took me about 20 seconds to find an example where they were  
>>> different
>>> using typical objects in my workspace.  You have been at this for  
>>> about a
>>> year now. I think you are taking the easy route out, rather than  
>>> working
>>> some of these answers out by yourself.
>>
>> Furthermore the answer is readily available from the obvious help  
>> pages,
>> which you have been repeatedly directed to.
>
> I just realized that I meant to ask the difference between data.class
> and class, rather than typeof and storage.mode, as I have tried the
> example from ?data.class. And I get no differences between data.class
> and class. Would you please let me know the difference between them if
> there is any? Sorry for the confusion.
>
>> x=LETTERS
>> data.class(factor(x))                 # has a class attribute
> [1] "factor"
>> class(factor(x))                 # has a class attribute
> [1] "factor"
>> data.class(matrix(x, ncol = 13))      # has a dim attribute
> [1] "matrix"
>> class(matrix(x, ncol = 13))      # has a dim attribute
> [1] "matrix"
>> data.class(list(x))                   # the same as mode(x)
> [1] "list"
>> class(list(x))                   # the same as mode(x)
> [1] "list"
>> data.class(x)                         # the same as mode(x)
> [1] "character"
>> class(x)                         # the same as mode(x)
> [1] "character"

Yet another question which the help page answers.

>>
>>

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list