Two R questions:
- What is the difference between the type (returned by
typeof) and the class (returned byclass) of a variable? Is the difference similar to that in, say, C++ language? - What are possible types and classes of variables?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In R every "object" has a
modeand aclass. The former represents how an object is stored in memory (numeric, character, list and function) while the later represents its abstract type. For example:As you can see data frames are stored in memory as
listbut they are wrapped intodata.frameobjects. The latter allows for usage of member functions as well as overloading functions such asprintwith a custom behavior.typeof(storage.mode) will usually give the same information asmodebut not always. Case in point:The reasoning behind this can be found here:
The link that I posted above also contains a list of all native R
basic types(vectors, lists etc.) and allcompound objects(factors and data.frames) as well as some examples of howmode,typeofandclassare related for each type.