R generates errors while assigning an object

I have probably a rather simple question but R produces constantly errors if I try to assign a variable.

Example:

x <- c(1, 2, 3)
mean(x)

If I run this code in a R script the console reports the following error message:

Error in mean(x) : object 'x' not found

If I run the same code in the console everything works. I don't know why this happens right now, it worked in the past.

Hi, and welcome to community.rstudio.com!

Just to troubleshoot - since you're working with a script, have you made sure to actually run the line x <- c(1, 2, 3) before running mean(x)?

3 Likes

Oh, you are right.
I was working until now only in the DataCamp environment.
Thanks for the reply - Just started with R :slight_smile:

If your question's been answered, would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

Sure, will do.
Thanks a lot!
Chris