I have a huge df whose columns contain genetic data (dosage counts). I have a list (a vector) of the index of the columns which are of no use for my analyses (they display only one value for all the rows) and I am trying to subset the df using this information. I went through some attempts (apply(), subset(), for loops), but I seem to be missing the point.
df <- data.frame(
k = c(0,1,1,0,0,1), d = c(0,1,0,2,0,1), p = c(0,0,0,0,0,0),
f = c(1,1,-9,0,0,0), t = c(0,0,-9,0,0,0), q = c(0,-9,0,0,0,0),
y = c(1,0,1,0,1,0), r = c(0,0,0,0,0,-9) )
index <- vector(3,5,6,8)
>df
k d p f t q y r
1 0 0 0 1 0 0 1 0
2 1 1 0 1 0 -9 0 0
3 1 0 0 -9 -9 0 1 0
4 0 2 0 0 0 0 0 0
5 0 0 0 0 0 0 1 0
6 1 1 0 0 0 0 0 -9
What I'm trying to get
>df
k d f y
1 0 0 1 1
2 1 1 1 0
3 1 0 -9 1
4 0 2 0 0
5 0 0 0 1
6 1 1 0 0```