The data:
Itun <- data.frame(v1 = c(1,1,2,1,2,1), v2 = c(NA, 1, 2, 1, 2, NA))
This will remove all columns containing at least one NA
:
Itun[ , colSums(is.na(Itun)) == 0]
An alternative way is to use apply
:
Itun[ , apply(Itun, 2, function(x) !any(is.na(x)))]
More Related Contents:
- How do I replace NA values with zeros in an R dataframe?
- Replacing character values with NA in a data frame
- How to replace NA values in a table for selected columns
- Omit rows containing specific column of NA
- Count NAs per row in dataframe [duplicate]
- Subset of rows containing NA (missing) values in a chosen column of a data frame
- How to subset data in R without losing NA rows?
- How to delete columns that contain ONLY NAs?
- Randomly insert NAs into dataframe proportionaly
- Select last non-NA value in a row, by row
- Replace in a factor column
- Replace all NA with FALSE in selected columns in R
- Find columns with all missing values
- R: replacing NAs in a data.frame with values in the same position in another dataframe
- Move NAs to the end of each column in a data frame
- Drop unused factor levels in a subsetted data frame
- Remove columns with zero values from a dataframe
- How to convert dataframe into time series?
- Merge unequal dataframes and replace missing rows with 0
- Add extra level to factors in dataframe
- finding close match from data frame 1 in data fame 2
- Combine several data frames in the global environment by row (rbind)
- Changing Million/Billion abbreviations into actual numbers? ie. 5.12M -> 5,120,000 [duplicate]
- Extract text after “/” in a data frame column
- use multiple columns as variables with sapply
- Creating (and Accessing) a Sparse Matrix with NA default entries
- Deleting specific rows from a data frame
- Count number of non-NA values for every column in a dataframe [duplicate]
- Divide each value by the sum of values by group
- Convert all data frame character columns to factors