R语言中的factor数据类型是什么 [英] What is factor Datatype in R Language

查看:477
本文介绍了R语言中的factor数据类型是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友,在实践Azure ML时,我用R语言进入了Fator数据类型,那是什么?

Hi Friends while Practicing Azure ML,I came into Fator Datatype in R-Language,what is that?

推荐答案

通过使其成为变量,告诉R变量是名义上的.该因子将标称值存储为[1 ... k]范围内的整数矢量(其中k是标称变量中唯一值的数量), 以及一个内部字符串向量(原始值)映射到这些整数.

Tell R that a variable is nominal by making it a factor. The factor stores the nominal values as a vector of integers in the range [ 1... k ] (where k is the number of unique values in the nominal variable), and an internal vector of character strings (the original values) mapped to these integers.

#30女性";条目
性别<-c(rep("male",20),rep("female",30)) 
性别<-factor(gender) 
#将性别存储为20 1s和30 2s并关联
#1 =女性,2 =内部为男性(按字母顺序)
#R现在将性别视为名义变量 
摘要(性别)

# variable gender with 20 "male" entries and 
# 30 "female" entries 
gender <- c(rep("male",20), rep("female", 30)) 
gender <- factor(gender) 
# stores gender as 20 1s and 30 2s and associates
# 1=female, 2=male internally (alphabetically)
# R now treats gender as a nominal variable 
summary(gender)

有序因子用于表示常规变量.

评分<-有序(rating)
#将等级重新编码为1,2,3,并关联
#1 =大,2 =中,3 =小内部
#R现在将等级视为序号

# variable rating coded as "large", "medium", "small'
rating <- ordered(rating)
# recodes rating to 1,2,3 and associates
# 1=large, 2=medium, 3=small internally
# R now treats rating as ordinal

在统计过程和图形分析中,R将因子视为名义变量,将有序因子视为序数变量.您可以在 factor()有序( )功能来控制整数到字符串的映射(覆盖字母顺序).您还可以使用因子来创建值 标签.

R will treat factors as nominal variables and ordered factors as ordinal variables in statistical proceedures and graphical analyses. You can use options in the factor( ) and ordered( ) functions to control the mapping of integers to strings (overiding the alphabetical ordering). You can also use factors to create value labels.

此致

雨桐


这篇关于R语言中的factor数据类型是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆