Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to understand the order factor and disorder factor in R language

Shulou Source: shulou.com Published: 2022-06-01 21:56:01 10月05日 Update

This article shows you how to understand the order factor and disorder factor in R language. The content is concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

A factor is a vector object that assigns a discrete classification (grouping) to its components, and its components are made up of other vectors of equal length. R provides order factor and disorder factor.

To put it popularly, a factor is to divide the values of an object into different groups (levels).

Create a factor with the function factor (), levels in alphabetical or numerical order.

For example, province pf pf prints out

[1] Sichuan Hunan Jiangsu Sichuan Hunan Jiangsu Jiangsu

Levels: Hunan, Jiangsu and Sichuan

The function levels () can be used to see how many different levels there are in the factor.

If we have the scores of candidates from these provinces:

> score smeans smeans

Hunan, Jiangsu and Sichuan

85.66667 91.00000 87.50000

For example, the following command gives the length of each group

> tapply (score,pf,length)

Hunan, Jiangsu and Sichuan

3 3 4

The function ordered () can create an order factor

> ordered (province)

[1] Sichuan Hunan Jiangsu Sichuan Hunan Jiangsu Jiangsu

Levels: Hunan < Jiangsu < Sichuan

The above content is how to understand the order factor and disorder factor in R language. have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Sichuan Factor Jiangsu Hunan function order component language difference content score Parameter Vector object that is skill knowledge conciseness popularity conciseness Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Microsoft NVidia Redmi Shulou Information