R programming: Unexpected symbol error

0 votes

I'm new to R programming, I tried this simple function:

myfunction <- function(y){
     y <- rnorm(100)
     mean(y) 
}

myfunction()
[1] 0.05248908
dir()
[1] "myfunction.R"
source("myfunction.R")

I get the following error:

Error in source("myfunction.R") : myfunction.R:2:3: unexpected symbol 1: 2: R version

Dec 17, 2018 in Data Analytics by Tyrion anex
• 8,280 points
136 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Format your code this way:

myfunction <- function() {
  z <- rnorm(100)
  mean(z)
}

Let me know if this works.

answered Dec 17, 2018 by Sophie may
• 9,330 points

Related Questions In Data Analytics

0 votes
1 answer

Error in source("myfunction.R") : myfunction.R:2:3: unexpected symbol 1: 2: R version

Try formatting your code like this: myfunction <- ...READ MORE

answered Oct 30, 2018 in Data Analytics by Maverick
• 10,020 points
102 views
0 votes
1 answer

Error: could not find function - R Programming

This error usually occurs when a package ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,020 points
176 views
0 votes
1 answer
0 votes
1 answer

"no applicable method" Error in r programming

This is caused by using an object-oriented ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 36,420 points
40 views
0 votes
1 answer

R programming error

Alright, you can either use gsub to match the ...READ MORE

answered Dec 18, 2018 in Data Analytics by Tyrion anex
• 8,280 points
11 views
0 votes
1 answer

R Programming: Market Basket Analysis Error

The basket.sorted() has less than 5 rules. Refer ...READ MORE

answered Feb 11 in Data Analytics by Sophie may
• 9,330 points
75 views
0 votes
1 answer

R Programming: regexpr error

The below code will help: gregexpr("D", x) # [[1]] # ...READ MORE

answered Feb 21 in Data Analytics by Tyrion anex
• 8,280 points
19 views
0 votes
1 answer

R programming: Graphs

Try this: ggplot(dfc, aes(x=x, y=y, colour=f, fill=f, ymin=y-se, ...READ MORE

answered Feb 21 in Data Analytics by Tyrion anex
• 8,280 points
17 views
0 votes
1 answer

R Programming error in 'fert'

You're using a factor: fert <- factor(c(50,20,10,10,20,50)) levels(fert) #[1] ...READ MORE

answered Dec 27, 2018 in Data Analytics by Sophie may
• 9,330 points
36 views
0 votes
1 answer

R programming: Missing value error

You can achieve this by wrapping isTRUE() around your if-condition: for ...READ MORE

answered Jan 24 in Data Analytics by Sophie may
• 9,330 points
29 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.