Get access to all lessons in this course.
-
Welcome to Data Cleaning with R
- What is Data Cleaning?
- Course Logistics and Materials
-
Data Organization
- Data Organization Best Practices
- Tidy Data
- Grouping and Indicator Variables
- NA and Empty Values
- Data Sharing Best Practices
-
Restructuring Data
- Tidyverse Refresher
- Working with Columns with across()
- Pivoting Data
- coalesce() and fill()
-
Regular Expressions
- What are Regular Expressions?
- Understanding and Testing Regular Expressions
- Literal Characters and Metacharacters
- Metacharacters: Quantifiers
- Metacharacters: Alternation, Special Sequences, and Escapes
- Combining Metacharacters
- Regex in R
- Regular Expressions and Data Cleaning, Part 1
- Regular Expressions and Data Cleaning, Part 2
-
Common Issues
- Common Issues in Data Cleaning
- Unusable Variable Names
- Whitespace
- Letter Case
- Missing, Implicit, or Misplaced Grouping Variables
- Compound Values
- Duplicated Values
- Broken Values
- Empty Rows and Columns
- Parsing Numbers
- Putting Everything Together
Data Cleaning with R
Empty Rows and Columns
This lesson is locked
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.
If the video is not playing correctly, you can watch it in a new window
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.
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))