我找不到下面的代码不起作用的原因。
with(df, {a<-plot(x,y) b<-lines(x1,x2)})
Run Code Online (Sandbox Code Playgroud)
然后我找到了一些使用以下语法的示例。
with(df, {a<-plot(x,y)
b<-lines(x1,x2)})
Run Code Online (Sandbox Code Playgroud)
当我使用第二种语法时,我没有收到任何错误。我缺少什么?
如果您希望两个命令位于同一行,请用分号分隔它们
with(df, {a<-plot(x,y); b<-lines(x1,x2)})
Run Code Online (Sandbox Code Playgroud)
这并不是withor独有的{}。你不能只是做
a <-5 b<-3 a+b # syntax error if on the same line.
Run Code Online (Sandbox Code Playgroud)
在 R 中并运行它。您希望 R 运行的单独语句之间需要分号或换行符。