Published on Feb 22,2017
465 Views
Email Post

## Importing SPSS Data in R

SPSS is a widely used statistical tool with popular usage among market researchers, health researchers, survey companies, government, education researchers, marketing organizations and data miners. In this tutorial, we shall learn the basic steps of importing SPSS data in R.

## Obtaining Values in SPSS:

1)In order to start with SPSS, it is important to install the library, ‘foreign’.

Command line is:  >Install library ‘foreign’

Also, it must be made sure that the file is saved in working directory.

2)Before going through this step, it is important to set a working directory as well.

Command line is: Set wd(“file address”)

3)Say for example, the file is in C drive under the folder utility, then:

Command line is: Set wd(“C:/utility”)

In this case, we firstly read the cancer data, then the class of cancer data, which is in the list.

We also have the option to convert the list into a data frame.

4)Here, we have ‘as.data.frame(cancer data in this case) converted into a data frame.

5)Once it is done, names in the data are accessible.

6)It also shows the top 6 Rows of the Cancer data.

7)If you have obtained a data frame and it goes null, then it is valid.

It helps you find the top 6 rows in the data as well. It is important to have error checks and make sure if data frames contain any values. Any data frame that obtains a null value is said to be valid.

## Removing rows and columns :

In a given 4×4 Matrix given below, the steps to remove rows and columns are demonstrated

For the matrix column

R/C        [1]   [2]    [3]   [4]

[1]          1      5       9      13

[2]           2     6      10    14

[3]           3     7      11     15

[4]           4      8      12     16

The statement is as below:

A[-c(1,3), -c(1,3,4)] – we are getting rid of rows 1 & 3 and columns 1,3 & 4.

A=matrix(1:16,4,4) will give a matrix of 4 rows and 4 columns, where the rows 1 & 3 and columns 1,3 & 4 are removed.

Got a question for us? Mention them in the comments section and we will get back to you.

Related Posts:

Introduction to Business Analytics with R