How can I define Global Variables in R

0 votes
Apr 25, 2018 in Data Analytics by zombie
• 3,790 points
5,741 views

1 answer to this question.

0 votes
The variables declared inside a function are local to that function.
For e.g.:

foo <- function() {
    m <- 2
}
foo()
m    //gives the following error: Error: object 'bar' not found.

If you want to make m a global variable, you should do:

foo <- function() {
    m <<- 2
}
foo()
m //In this case m is accessible from outside the function.
answered Apr 25, 2018 by shams
• 3,670 points

Related Questions In Data Analytics

0 votes
1 answer

How can I get type of all variables in R?

It is a easy task and one ...READ MORE

answered May 22, 2018 in Data Analytics by zombie
• 3,790 points
885 views
0 votes
1 answer

How to set global variables in R

To set global variables, you can use ...READ MORE

answered Apr 24, 2018 in Data Analytics by kappa3010
• 2,090 points
998 views
0 votes
1 answer

How can I control the size of points in an R scatterplot?

plot(variable, type='o' , pch=5, cex=.3) The pch argument ...READ MORE

answered May 3, 2018 in Data Analytics by shams
• 3,670 points
1,050 views
0 votes
1 answer

How can I select a CRAN mirror in R ?

There are many ways of doing so ...READ MORE

answered May 9, 2018 in Data Analytics by zombie
• 3,790 points
734 views
0 votes
1 answer

How can I rotate axis labels in R ?

library(ggplot2) p <- data.frame(Day=c("2011-04-11", "2014-05-24","2004-01-12","2014-06-20","2010-08-07","2014-05-28"), Impressions=c(24010,15959,16107,21792,24933,21634),Clicks=c(211,106,248,196,160,241)) p       ...READ MORE

answered May 18, 2018 in Data Analytics by zombie
• 3,790 points
1,663 views
0 votes
1 answer

How can I Split code over multiple lines in an R script?

You can do this as follows: setwd(paste("~/a/very/long/path/here ...READ MORE

answered May 22, 2018 in Data Analytics by zombie
• 3,790 points
1,728 views
0 votes
1 answer

How can I find file name from full file path in R?

You can use: basename("C:/some_dir/filename.ext") # [1] "filename. ...READ MORE

answered May 24, 2018 in Data Analytics by zombie
• 3,790 points
1,142 views
0 votes
1 answer

How can I pause, sleep, wait, execution for X seconds in R?

You can try the following piece of ...READ MORE

answered May 25, 2018 in Data Analytics by zombie
• 3,790 points
1,848 views
0 votes
1 answer

How can I delete multiple values from a vector in R?

The %in% operator tells  which elements are ...READ MORE

answered Apr 27, 2018 in Data Analytics by shams
• 3,670 points
5,949 views
0 votes
1 answer

How can I remove duplicated rows in R ?

The function distinct() in the dplyr package ...READ MORE

answered Apr 27, 2018 in Data Analytics by shams
• 3,670 points
2,713 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP