For this example we will have a data file with two columns of data labelled A and B. For example

A    B
0.1 0.2
0.3 0.4
0.5 0.6

Set the working directory and load the data as usual in r:

data = read.table("data.txt", header=T)
names(data) # List the header names


Find the correlation between A and B.

cor(data$A, data$b)

If you have more than 2 variables calculate the correlation matrix using :


Unstandardised Regression Coefficient

A predicting B


Standardised Regression Coefficient

A predicting B

lm( scale( data$B )~scale( data$A ) )