1.9 Removing Records with Missing Data
In the post number 1.5 Dealing with missing data, we saw various methods and lets implement few of those in this tutorial. First of all let's have a look at the CSV file.

We see that, we have decided the option of removing rows where values in Industry column are missing.
Before proceeding to the R, I would suggest you to always make a back up of the data so that in case you do any mistake in between you always have the original data to start again. Let's create the backup of our fin dataset.
.
And this one line can save us a lot of trouble.
Now, let's find out all of the rows that have empty value in any of the column.
We see two rows where values in Industry column is missing. Let's single out these rows using is.na()

So we got two rows with ID 14, 15 where value in Industry column is missing. Now to remove these two rows, we just do the opposite and find out the rows which don't have NA in them and assign it back to the fin dataset.

Using the above command we see that, row number 14 and 15 are deleted. We run complete.cases() on the dataset once again and see that the rows having NA are reduced by two because we just now dealt with them.
We see that, we have decided the option of removing rows where values in Industry column are missing.
Before proceeding to the R, I would suggest you to always make a back up of the data so that in case you do any mistake in between you always have the original data to start again. Let's create the backup of our fin dataset.
And this one line can save us a lot of trouble.
Now, let's find out all of the rows that have empty value in any of the column.
So we got two rows with ID 14, 15 where value in Industry column is missing. Now to remove these two rows, we just do the opposite and find out the rows which don't have NA in them and assign it back to the fin dataset.
Using the above command we see that, row number 14 and 15 are deleted. We run complete.cases() on the dataset once again and see that the rows having NA are reduced by two because we just now dealt with them.
Comments
Post a Comment