To delete empty rows in R, we can use the complete.cases()
function which returns a logical vector indicating which observations are complete cases (i.e., rows with no missing data). We can then use this logical vector to subset our data frame and retain only those rows that are not empty.
Here's an example code to remove empty rows from a data frame df
:
main.r30 chars2 lines
In the above code, complete.cases(df)
returns a logical vector indicating which rows are complete cases. This vector is used to subset the original df
, retaining only those rows that are complete cases (i.e., not empty).
Alternatively, we can also use the na.omit()
function to remove any rows with missing values (i.e., empty rows) from the data frame:
main.r18 chars2 lines
Here, the na.omit()
function returns the original data frame with any rows containing missing (NA) values removed.
gistlibby LogSnag