Showing posts with label r. Show all posts
Showing posts with label r. Show all posts

Saturday, December 21, 2013

Installing packages in R

Installing packages in R

Like indicated in the introduction of the tutorial, R is a open source software package. This makes it free for everyone to develop different applications that could be applied to the R console. Such a application is called a package. Examples of packages are:
  • Zelig: To make more sophisticated calculations for a regression analysis;
  • Foreign: Installation of this package will make R able to read more types of files.
When you have downloaded R, no additional packages are installed. In the first place this is not a problem since you could perform quite good data analysis with R without additional packages installed. For example, the calculations in this tutorial do not require additional packages. 

If you want to install packages in the R console, you can do this as follows:
Enter the command available.packages(). If you press enter, a window appears where you have to choose a mirror. Select a mirror that mostly fits your location. 

If you have done this, a list of packages appears that are ready for installation. If you have found a package, copy the name of that package and past this in the following command: install.packages('*name of the package that you want to install*'). By pressing Enter the package gets installed and R indicates in which folder this package is located.

Installing packages in R
Installing packages in R

Friday, December 20, 2013

List of R commands

List of R commands


*name of new variable*<-c(value,value,value,......more values)

Assigning a variable based on a value or a string of values.

*name of new variable*<-*data or more values*

Assigning a variable to a dataset or other value.

attach(*variable*)

Making a matrix of a variable of a dataset.

min(*variable*) or min(*variable*, *vraibale* ….more variables)

Finding the minimum value from a variable or from a string of variables.

max(*variable*) or max(*variable*, *variable* ….more variables)

Finding the maximum value from a variable or string of variables.

lenght(*variable*)

Showing the number of values of a variable.

sum(*variable*)

The sum of all values of a specific variable.

mean(*variable*)

Showing the mean (average) of the values from a variable.

sd(*variable*)

Showing the standard deviation of the values from a variable.
detach(*variabele*)
Detach a matrix from a variable.

median(*variabele*)

Calculating the median from the values that a variable contains.

cor(*variabele1*, *variabele2*)

Showing the correlation between two variables.

plot(*variabele1*, *variabele2*)

Plotting a graph from two variables.

hist(*variabele*)

Making a histogram of a variable.

Making a boxplot of a variable.

barplot(*variable 1*, *variable 2*, more variables)

Making a bar graph of variables.

dotplot(*variable 1*, *variable 2*)

Making a dot plot of two variables.

pie(*variable*)

Making a pie chart of a variable.

*variable*[*position or name of variable 1*, *position or name of variable 2*]

Finding a value in the matrix of a variable.

read.csv(‘*name of a csv-file*’)

Importing a csv-file in R.

*name of the regression*<-lm(*dependent variable*~*independent variable 1*+*independent variable 2*+*more independent variables*)

Making a regression analysis with a dependent varaibele or one of more independent variables.

summary(*name of the regression*)

Showing the results and data of the regression analysis.