R-mode (mode) and classes (class)

Source: Internet
Author: User

Data Mode: The Mode function displays the pattern of any object. of common singleThe object pattern is a logical (Logical), numeric (Numeric), character (Character) type. The commonly used data pattern is the list.
    • Logical: True and FALSE are uppercase letters, true->1,false->0 when converted to numeric.
    • Character type: Single or double quotation marks can be used when entering character type, and double quotation mark when output
    • List: Allows data in multiple modes, and a data frame is a list. matrices, vectors, and so on require all data to be in the same pattern.

conversion between data schemas :

    • as.character-> conversion to character type
    • as.numeric-> character-type conversion numerical type
    • as.logical-> character-type conversion logic

Data type : Class function Displays the classes of the object. Common vector (vertor), data frame (frame), Matrix, Factor (Factor).

    • Factor: Special processing of factors in statistical modeling and cartographic functions. But when the mode function is checked, it is returned as a numeric type .
    • Date and time: Although can be stored in character type, but inconvenient to special treatment.

Lists allow multiple patterns of data, and you can use the Sapply function when you want to get the patterns and classes for each component:

> mylist = List (a = C (n/a), B = C (' A ', ' B ', ' C '), C = C (true,false), d = factor (' house '));

> sapply (Mylist,mode)

A B c D

"Numeric" "character" "Logical" "numeric"

> sapply (Mylist,class)

A B c D

"Numeric" "character" "logical" "factor"

R-mode (mode) and classes (class)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.