Subsetting all Rows with NA (Missing Value) in any of the columns

amrrs

I've a dataset (teleco) with 3000 obs and there are many (332) missing value (NA)s in it. When i try to subset all the missing values into another dataframe, I strangely endup with 3745 obs.

clean = na.omit(teleco)
new = teleco[is.na(teleco[1:19])==TRUE, ]

clean - 2668 obs of 19 vars

new - 3745 obs of 19 vars

teleco - 3000 obs of 19 vars

I'm sure that i'm doing something wrong. Can someone please help?

akrun

If we need to subset rows having at least one NA, we can create an index using rowSums on the logical matrix (is.na(teleco)), and convert that to a logical vector (!=0).

teleco[rowSums(is.na(teleco))!=0,]

Or we can use apply with MARGIN=1 to create a logical vector.

teleco[apply(is.na(teleco), 1, any),]

data

set.seed(24)
teleco <- as.data.frame(matrix(sample(c(NA,0:10), 20*5, replace=TRUE), ncol=5))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

!is.na Remove columns with NA value (in any rows)

How to filter for rows across any columns for na and 0 but not with true value

Python: Assign missing value to rows in one column if any row is missing value in other columns

na.omits removes all rows with NA in any column and not only on the specified columns

Pandas: How to include all columns for all rows although value is missing in a dataframe with a long format?

mutate columns after subsetting by value

R - Filter any rows and show all columns

Select rows where only one column has a value and all other columns have NA

Subsetting rows in data.table where one column is not NA and the values in a list of other columns have exactly one NA

Subsetting each 5 rows into 5 columns

Remove rows having same value in all columns

Remove rows with the same value across all columns

Count rows that have same value in all columns

Insert all missing rows into data table for a range of values for 2 columns

Subsetting Rows with a Column Value Greater than a Threshold

Subsetting columns based on single value in row

Select Rows That Does Not Contain any Negative Or Missing Value

How to apply TextBlob if value in columns are missing for some rows?

Pandas - DF with lists - find all rows that match a string in any of the columns

Find dataframe rows with all of list of strings in any of list of columns

Drop all rows that *do not* contain any NaNs in their columns

Select rows with matching columns and all columns match a value for id

Remove rows in a dataframe if ALL values in a selection of columns returns NA as result

Pandas: Find rows where a particular column is not NA but all other columns are

How to group_by and then summarise which rows have NA in all columns

Drop dataframe columns where all rows AND header is na

Subsetting on NA

How can I remove any rows that have missing data within a specific range of columns and on only specific rows?

Filtering all rows if any value in a row is less than a threshold value