Assignment

Objects obtain values in R by assignment (‘x gets a value’). This is achieved by the gets arrow <- which is a composite symbol made up from ‘less than’ and ‘minus’ with no space between them. Thus, to create a scalar constant x with value 5 we type

x<-5

and not x = 5. Notice that there is a potential ambiguity if you get the spacing wrong. Compare our x<-5, ‘x gets 5’, with x <-5 which is a logical question, asking ‘is x less than minus 5?’ and producing the answer TRUE or FALSE.

Get The R Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.