在RStudio编辑器中,那些带有红色线和点的是什么?

huangapple go评论71阅读模式
英文:

What are those red lines with dots in RStudio editor

问题

当使用havenread_sav从SPSS导入数据时,我得到一些values,如"1. Tout à fait d?accord""2. Plutôt d?accord"

这些数值似乎在句点和文本之间有空格,然而,它们实际上不是"正常"的空格,因为无法使用它们引用它们(即%>% filter(values == "1. Tout à fait d?accord")将不起作用。

一个朋友告诉我,在STATA中打开数据,然后将这些行复制到RStudio编辑器中,会产生这些奇怪的红色字符(如图所示),现在代码可以运行。如何在不经过STATA的情况下在R中适当读取这些数据?

英文:

When importing data from SPSS with haven's read_sav I get some values like "1.     Tout à fait d?accord" or "2.     Plutôtd?accord".
Those values seem to have whitespaces between the period and the text, however, they are not actually "normal" whitespaces, as they can't be referenced using them (i.e. %>% filter(values == "1. Tout à fait d?accord")) won't work.

A friend told me that opening the data in STATA and then copying the lines to RStudio editor produced these weird red characters (shown in image), and the code now works. How can I read these data in R adequately without going through STATA?

在RStudio编辑器中,那些带有红色线和点的是什么?

答案1

得分: 1

Are you sure that these have 4 white spaces? It is quite likely that the data has tab as spaces which is different.
When you write into a text editor:

"I'm    tab    separated"

Then copy it to the console to assign it in R:

TestString <- "I'm    tab    separated"

To test whether it is the same as 4 white spaces we can run the following test.

# With 4 white spaces
TestString == "I'm    tab    separated"
[1] FALSE
# Tab separated
TestString == "I'm\ttab\tseparated"
[1] TRUE

By knowing this you can either replace the tab in the file or just address it during the subsetting (which is probably better).

英文:

Are you sure that these have 4 white spaces? It is quite likely that the data has tab as spaces which is different.
When you write into a text editor:

&quot;I&#39;m    tab    separated&quot;

Then copy it to the console to assign it in R:

TestString &lt;- &quot;I&#39;m    tab    separated&quot;

To test whether it is the same as 4 white spaces we can run the following test.

# With 4 white spaces
TestString == &quot;I&#39;m    tab    separated&quot;
[1] FALSE
# Tab separated
TestString == &quot;I&#39;m\ttab\tseparated&quot;
[1] TRUE

By knowing this you can either replace the tab in the file or just address it during the subsetting (which is probably better).

huangapple
  • 本文由 发表于 2023年4月4日 16:55:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75927377.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定