R中的全局变量 [英] Global variables in R

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

问题描述



问题2:如何在函数中设置全局变量?

关于绘图,

我在一张纸上绘制了多张图,并且为了区分它们中的每一张,我想为它们中的每一张添加标题。任何人都可以告诉我怎么做到这一点?

解决方案

每个主要问题使用一个帖子。


  1. 正如assign()向你展示的第一个答案所示,有一种方法可以在全局环境中进行分配。使用<< - < $ code>运算符,即更简单,更短(但不是更好的)分配方式,即

      a<<  - 新



  2. 为每个情节。使用类似于 par(mar = c(3,3,3,1))的东西来给出足够的间隔。



      I am poking into the manuals, I wanted to ask the community: How can we set global variables inside a function?

      Question-2: Regarding plotting,

      I am using plotting multiple graphs in a single sheet, and to differentiate each one of them, I want to add title for each one of them. Can anyone tell me how I can achieve this?

      解决方案

      Use one post per main question.

      1. As the first answer with assign() showed you, there is a way to assign in the global environment. A simpler, shorter (but not better ... stick with assign) way is to use the <<- operator, ie

        a <<- "new" 
        

        inside the function.

      2. For your plots, use main="My title here" for each plot. Use something like par(mar=c(3,3,3,1)) to give sufficient spacing.

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

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