R中的变量名限制 [英] Variable name restrictions in R

查看:154
本文介绍了R中的变量名限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于R中的变量名可以使用哪些字符(可能还有其他限制)有什么限制?

What are the restrictions as to what characters (and maybe other restrictions) can be used for a variable name in R?

(这是普遍参考的尖叫,但我似乎找不到答案)

(This screams of general reference, but I can't seem to find the answer)

推荐答案

您可能正在寻找?make.names中的讨论:

You might be looking for the discussion from ?make.names:

在语法上有效的名称由字母,数字和点或 带下划线的字符,并以字母或点开头 一个数字.诸如".2way"之类的名称无效, 保留字.

A syntactically valid name consists of letters, numbers and the dot or underline characters and starts with a letter or the dot not followed by a number. Names such as ".2way" are not valid, and neither are the reserved words.

在帮助文件本身中,有一个指向保留字的列表的链接,这些保留字是:

In the help file itself, there's a link to a list of reserved words, which are:

如果在下一个中断中重复执行while函数

if else repeat while function for in next break

TRUE否NULL Inf NaN NA NA_integer_ NA_real_ NA_complex_ NA_character _

TRUE FALSE NULL Inf NaN NA NA_integer_ NA_real_ NA_complex_ NA_character_

评论中的许多其他好的注释包括James指出的问题,用于检查语法上有效的名称.

Many other good notes from the comments include the point by James to the R FAQ addressing this issue and Josh's pointer to a related SO question dealing with checking for syntactically valid names.

这篇关于R中的变量名限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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