Getting Started

Once you decided to study R, If somebody help you, then you will be very happy. Next we will discuss how we proceed further once you opened R.

Click Ctrl+L. what will happened to R interface? To know about Ctrl+L clik on console menu in the help menu. You can find out more shortcut key in console.

How to start with help command. Type help(mean), so that it will give all information about mean. This command can also be written as ?mean. If you type ??mean, a separate window will list all the command containing mean. Other wise use help.search("mean"). With these two help command you can find out anything, but we shall discuss something more here.

Whether you want to write some program first or do some data analysis. If you want to do some analysis using the inbuilt command in R, first we need to enter the data. For importing data from external file please go to the input section of the R notes. You can enter the data in different data types including scalars, vectors, matrices, data frames.

The vector can be entered like

x=c(1,3,6,10,15)

x=1:20

x=c(rep(10,4),12)

x=c("male", "female") # character vector

A matrix can be created using the command

matrix <- matrix(vector, nrow=r, ncol=c,)

Try

x=matrix(c(2,3,4,5),2,2) and x=matrix(c(2,3,4,5),2,2,byrow=T).

Note that byrow=T indicates that the matrix should be filled by rows, otherwise the matrix should be filled by columns (the default).

If you want to enter different type of data in different column, you can use data.frame. Please not that the variable should have the same length. Using data.frame the variables can be stored as in SPSS or in Excel.

a=c(20,23)

b=c("M","F")

sudheesh=data.frame(a,b)

names(sudheesh)=c("Age","Gender")

attach(sudheesh) # to identify the variable

The command factor and ordered can be use to define the variable in nominal and ordinal form.

Suppose you enter x and y in a matrix form you want to combine them, use

z=cbind(x,y)# combine objects as columns

or

z=rbind(x,y) #combine objects as rows

Last, if you want to edit some variable as well as the data set use

Agenew=edit(Age) or sudheeshnew=edit(sudheesh)

Let us start working! 

 

back to notes