how to write an R script that takes from the user a list of numbers and do some mathematical operations on it ?
i want to know how to write R script that takes from the user a list of numbers and outputs the following of the list:
- Mean and median.
- Standard deviation and range.
i want it to receive any input data from the keyboard and display data on the screen.
here the script that i used :
num <- readline (prompt = "list of numbers")
num <- as.numeric(num)
result.mean <- mean(num)
print (result.mean)
result.median <- median(num)
print(result.median)
result.sd <- sd(num)
print(result.sd)
but it didnt work and i'm sorry if the script not in correct format but i dont know how to display it .
• 1,799 views
•
link
0 answers
No answers yet.
Log in to answer this question.
Please use the formatting bar (especially the

codeoption) to present your post better. I've done it for you this time.thanks alot
It only works for a single number input, if you wish to accept multiple numbers separated with comma or space, we need so split it on delimiter before converting to numeric. See related StackOverflow post: