# introtor.lecture2.vectors Welcome to R.

### Variable

Name rules:

• no space
• split with period(usually) or make every first letter in each word, except the first one, capital(Camel Notation) e.g. my.variable myVariable

Make sure that the name of your variable is highly readable and understandable.

### Assignment

• use <- (its="" shortcut="" in="" rstudio="" is="" alt="" -)="" e.g.="" x-="">5
• You can use ‘=’ for assignment, but we seldom write code is this way. While there’s an exception: when we assign values to parameters of a function, we use ‘=’ instead of <-.

### Environments

On the top right of the RStudio. The environment is where R stores the variables and their values.
To clean the environment:

In RStudio, all the notebooks open at the same time will ‘share’ the environment window.

## Vectors

### Create Vectors

numeric(10): default value is 0.
logical(5): default value is FALSE.
c(…) : list all the values and it can combine vectors together.

The output is 1 0 1 1 1 1.

The output is “1” “2” “3” “4” “hey” “5”

### The colon operator

The colon operator takes two numbers and produces a vector of numbers starting at the first value and ending at the second number in increments or decrements of 1.
The numbers does not have to be an interger.

The output is 1.2 2.2 3.2 4.2 5.2

The output is 2 1 0 1 2 3 4 5 6

### Random numbers

Thus, to generate 25 random values from a normal distribution with mean 100 and standard deviation 10, we have:

### Vectorized Operation

Vectorized operations are component-wise.
That means we applying the operation to corresponding elements in the same place.

The output is 3 5 7 9 11
The vectors can have different length and the operations are executed circularly, but it is quite strange to do so and there will be an warning in RStudio.
Also

The output is 7 11 15 19 23

Use sum() function to calculate the sum of all the element of vectors.

## Data Visualization: The Stripchart

Tips:
To be more professional, the charts should not be so colorful.