R language data structure--1 vector and factor ② factor-vector

Source: Internet
Author: User

June 8, 2018 today is the second day of learning R feel slow, need to speed up a bit. In addition yesterday seems to write not particularly good, so today intends to study the overall editor.

Today to learn the factors, first: what is a factor? Because we know the vectors in R, and because we've been learning python for a while, we have an understanding of dictionaries, arrays, etc. So, for the factor I can be seen as a vector with a little dictionary flavor. (Personal understanding)

The definition of Baidu is this: factors are used to store categorical variables (categorical variables) and ordered variables, which cannot be used to calculate but only to classify or count. Factors represent categorical variables, and ordered factors represent ordered variables.

That is, the factor is a class and ordered variable, the equivalent of dividing the variable into discrete and continuous, the factor is the discrete vector.

For example:!!!

> a=c (' A ', ' a ', ' B ', ' O ', ' ab ', ' ab ');
[1] "a" "a" "B" "O" "AB" "AB"

> X=factor (C (' A ', ' a ', ' B ', ' O ', ' ab ', ' ab ')); x
[1] A a b o ab AB
Levels:a AB b o

Note that the output in the factor will be output in the order of the Binary tab, so it will be a first and then AB then a will not be a B

R language data structure--1 vector and factor ② factor-vector

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.