Empty Rows and Columns
This lesson is called Empty Rows and Columns, part of the Data Cleaning with R course. This lesson is called Empty Rows and Columns, part of the Data Cleaning with R course.
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Your Turn
Import the Marine Protected Areas dataset (MPAS-your.csv)
Identify the empty rows and columns
Remove the empty rows and columns
Learn More
If you want to do even more with missing data, check out the naniar
package.
Have any questions? Put them below and we will help you out!
Course Content
32 Lessons
1
What are Regular Expressions?
03:48
2
Understanding and Testing Regular Expressions
03:51
3
Literal Characters and Metacharacters
06:16
4
Metacharacters: Quantifiers
01:33
5
Metacharacters: Alternation, Special Sequences, and Escapes
02:53
6
Combining Metacharacters
05:18
7
Regex in R
02:58
8
Regular Expressions and Data Cleaning, Part 1
04:15
9
Regular Expressions and Data Cleaning, Part 2
12:00
1
Common Issues in Data Cleaning
03:17
2
Unusable Variable Names
10:11
3
Whitespace
11:10
4
Letter Case
06:52
5
Missing, Implicit, or Misplaced Grouping Variables
11:19
6
Compound Values
10:09
7
Duplicated Values
08:49
8
Broken Values
09:52
9
Empty Rows and Columns
11:30
10
Parsing Numbers
12:02
11
Putting Everything Together
25:50
You need to be signed-in to comment on this post. Login.
Alberto Cabrera • January 13, 2024
In trying to remove both rows and columns with missing data using the following Luis' solution prompted the following error.
MPA <- MPAS_your |> remove_empty(which = "cols") |> filter(!across(-rank_by_extent, is.na))
Error in
filter()
: ℹ In argument:!across(-rank_by_extent, is.na)
. Caused by error: !..1
must be a logical vector, not a logical matrix.David Keyes Founder • January 15, 2024
It looks like the use of
across()
withinfilter()
was deprecated indplyr
1.0.8. You can change your code to use theif_any()
function instead as follows:Alberto Cabrera • January 15, 2024
It worked. Actually I tried the version below, when I received the deprecated message. I did not realize to qualify if_any with the negation. Many thanks for sending me the correct answer.
MPAS_your |> remove_empty(which = c("rows","cols")) |> filter(if_any(-rank_by_extent,is.na))
Alberto Cabrera • January 15, 2024
It worked. Actually I tried the version below, when I received the deprecated message. I did not realize to qualify if_any with the negation. Many thanks for sending me the correct answer.
MPAS_your |> remove_empty(which = c("rows","cols")) |> filter(if_any(-rank_by_extent,is.na))