I would like to remove columns that have less than 150 from the column sum from my dataframe df1
My dataframe is
chr leftPos FLD0195 FLD0197 FLD0201 FLD0203 FLD0211 FLD0243
chr1 100260254 34 52 29 18 13 30
chr1 100735342 44 111 88 65 40 66
chr1 100805662 0 0 1 1 0 0
chr1 100839460 1 0 5 0 0 0
The formula I'm using is as below. It runs without error but df2 is exactly the same as df1
df2 <- df1[,(colSums(df1[,3:ncol(df1)]) > 100000),]
df1[,3:ncol(df1)]while sub-setting from the whole data set. You should do something likecbind(df[1:2], df1[3:ncol(df1)][, colSums(df1[3:ncol(df1)]) > 150, drop = FALSE])df1[c(TRUE, TRUE, colSums(df1[3:ncol(df1)]) > 150)](adjust 150 to 1e5 in your original data)