R generates errors while assigning an object

rstudio

#1

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.


#2

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

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


#4

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:


#5

Sure, will do.
Thanks a lot!
Chris