delete column dataframe r code example
Example 1: drop columns by index r
df <- mydata[ -c(1,3:4) ]
df = subset(mydata, select = -c(x,z))
Example 2: r data frame remove column
df$columnName <- NULL
Example 3: drop a column in r data frame
df <- df %>%
select(-column_to_drop)
Example 4: remove column from matrix r
MyMatrix <- MyMatrix[,-3]
MyMatrix <- MyMatrix[,c(TRUE,TRUE,FALSE,TRUE,FALSE,TRUE)]
Example 5: how to exclude columns in r
> Data$genome <- NULL
> head(Data)
chr region
1 chr1 CDS
2 chr1 exon
3 chr1 CDS
4 chr1 exon
5 chr1 CDS
6 chr1 exon
Example 6: r remove column by index
DT[, coltodelete := NULL]