简体   繁体   English

我如何处理消息错误:R 中的意外符号?

[英]How do i handle the message Error: unexpected symbol in R?

I have to design three research questions using the dataset brfss2013 .我必须使用数据集 brfss2013设计三个研究问题。 The second one I am doing is Do people who drink and smoke some days have higher blood pressure than people who don't at all?我正在做的第二个问题是,某些天喝酒和抽烟的人的血压是否比根本不抽烟的人血压高? To view the data before visualizing it, I tried to create a subset narrowing down to people who smoke two or three times a week.为了在可视化之前查看数据,我尝试创建一个子集,将范围缩小到每周吸烟 2 到 3 次的人。

smokers <- subset(brfss2013, smokday2 == 2 | smokday2 == 3, select = c(smokday2, avedrnk2))

I ran the code above and got the following error:我运行上面的代码并得到以下错误:

Error: unexpected symbol in "smokday2 == 2 or"**错误:“smokday2 == 2 or”** 中的意外符号

I tried eliminating the "|"我尝试消除“|” symbol and the second piece of the subset argument making it:符号和子集参数的第二部分使得它:

smokers <- subset(brfss2013, smokday2 == 2, select = c(smokday2, avedrnk2))

But then got a table with zero rows.但是后来得到了一个零行的表。 Also, the data frame is very slow and out of sync in Rstudio so I can't examine brfss2013 very easily.此外,Rstudio 中的数据帧非常慢且不同步,因此我无法轻松检查 brfss2013。 It's also huge.它也很大。

Does anyone know what the issue is here?有谁知道这里的问题是什么?

Please let me know请告诉我

Funny story, I found the answer.有趣的故事,我找到了答案。 When I ran and didn't get a syntax error, I got a table with 0 rows.当我运行并且没有收到语法错误时,我得到了一个包含 0 行的表。 I found out that the data background/overview claims smokday2 has values such as "2" or "3", but when running brfss2013$smokday2 I found that it actually is populated with strings of text such as "Some days", "Not at all", and "Every day".我发现数据背景/概述声称 smokday2 具有诸如“2”或“3”之类的值,但是在运行 brfss2013$smokday2 时,我发现它实际上填充了诸如“Some days”、“Not at全部”和“每一天”。 Here is an example of the code I used for a functional subset:这是我用于功能子集的代码示例:

somesmokendrink <- subset(brfss2013, smokday2 == "Some days" & avedrnk2 == c(2:4), select = c(smokday2, avedrnk2)) somesmokendrink <-子集(brfss2013,smokday2 ==“某些日子”& avedrnk2 == c(2:4),选择= c(smokday2,avedrnk2))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM