Take the 2-minute tour ×

I have a simple dataset i.e.(1.22 -0.86 -1.35 -1.46 0.67 2.77 -0.50 0.34 -0.57 -0.05).
I would like to define this as a data set in R so I don't have to manually calculate the mean and variance and possibly plot this. How do I do this?
I have tried data<-[1.22 -0.86 -1.35 -1.46 0.67 2.77 -0.50 0.34 -0.57 -0.05] but I get Error: unexpected numeric constant in "data<-1.22 -0.86 -1.35 -1.46 0.67"

share|improve this question
add comment

4 Answers

up vote 8 down vote accepted
data <- c(1.22,-0.86,-1.35,-1.46,0.67,2.77,-0.50,0.34,-0.57,-0.05)

May I recommend http://cran.r-project.org/doc/manuals/R-intro.pdf ?

share|improve this answer
+1 for link to manuals –  Andrie Jul 21 '11 at 6:35
add comment

In addition to the previous responsese, if you use the scan function without setting any argument then it will expect the data to be entered from the command line with individual elements seperated by whitespace (spaces and newlines). An empty entry (pressing enter twice) will end the imput.

For a quick little dataset working at the command line this can be a quick and easy method to enter the data.

share|improve this answer
add comment

You could also put the numbers in a file, separated by spaces or new lines, and use 'scan':

data = scan("data.txt")
share|improve this answer
add comment

The 'c' function combines values into a list.

data<-c(1.22, -0.86 etc)


share|improve this answer
SNAP @ Ben Bolker –  Pete855217 Jul 21 '11 at 5:29
..."into a vector or list". –  Brandon Bertelsen Jul 21 '11 at 8:00
add comment

Your Answer


