Entering edit mode
3.0 years ago
m90
▴
30
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 .
Please use the formatting bar (especially the
code
option) 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: