R编码ASCII回车 [英] R encoding ASCII backtick

查看:236
本文介绍了R编码ASCII回车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的列表名称中有以下的反引号。以前的列表没有这个反驳。

  $`1KG_1_14106394` 
[1]PRDM2

$`1KG_20_16729654`
[1]OTOR

我发现这是一个ASCII严重口音,并读取R页面上的编码类型。但是怎么办呢?我不清楚这是否会影响一些功能(例如列表名称匹配),或者是否可以保持原样?



编码帮助页面: https://stat.ethz.ch/R-manual/R -devel / library / base / html / Encoding.html



谢谢!

解决方案

我的理解(可能是错误的)是,反驳只是一种转义列表名称的方法,否则如果未转义,则不能使用。使用反引号来引用列表名称的一个例子是包含空格的名称:

  lst < -  list 1,2,3)
名称(lst)< - c(one,after one,two)

如果您想参考包含第二个的列表元素,可以使用以下方式:

  lst [[after one]] 

但是,如果要使用美元符号符号,您将需要使用反引号:

  lst $`after one` 

更新:



发现此帖,其中讨论了与您相似的问题。如果变量名称被禁止,则变量名称中的反引号是必需的。空格是一个例子,但是使用保留关键字作为变量名。

  if<  -  3#被禁止,因为if是一个关键字
`if`< - 3#允许,因为我们使用反引号

在您的情况下:



您的列表中有一个名称为的元素开头的元素。 R中变量名称的规则是相当松散的,但是它们不能以数字开头,因此:

  1KG_1_14106394<  -  3 #失败,变量名以
开头KG_1_14106394< - 3#允许,以字母
`1KG_1_14106394`< - 3#开头,因为在反引号中转义


I have the following backtick on my list's names. Prior lists did not have this backtick.

$`1KG_1_14106394`
[1] "PRDM2"

$`1KG_20_16729654`
[1] "OTOR"

I found out that this is a 'ASCII grave accent' and read the R page on encoding types. However what to do about it ? I am not clear if this will effect some functions (such as matching on list names) or is it OK leave it as is ?

Encoding help page: https://stat.ethz.ch/R-manual/R-devel/library/base/html/Encoding.html

Thanks!

解决方案

My understanding (and I could be wrong) is that the backticks are just a means of escaping a list name which otherwise could not be used if left unescaped. One example of using backticks to refer to a list name is the case of a name containing spaces:

lst <- list(1, 2, 3)
names(lst) <- c("one", "after one", "two")

If you wanted to refer to the list element containing the number two, you could do this using:

lst[["after one"]]

But if you want to use the dollar sign notation you will need to use backticks:

lst$`after one`

Update:

I just poked around on SO and found this post which discusses a similar question as yours. Backticks in variable names are necessary whenever a variable name would be forbidden otherwise. Spaces is one example, but so is using a reserved keyword as a variable name.

if <- 3     # forbidden because if is a keyword
`if` <- 3   # allowed, because we use backticks

In your case:

Your list has an element whose name begins with a number. The rules for variable names in R is pretty lax, but they cannot begin with a number, hence:

1KG_1_14106394   <- 3  # fails, variable name starts with a number
KG_1_14106394    <- 3  # allowed, starts with a letter
`1KG_1_14106394` <- 3  # also allowed, since escaped in backticks

这篇关于R编码ASCII回车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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