I am attempting to perform an unconventional filter of a dataframe. I am looking to filter the columns of a dataframe that have a particular value in a row
To do this the other way around is quite easy using filter in dplyr but I can't seem to figure it out filtering by column instead of the conventional filtering by row.
I have tried using the dplyr filter command but I suspect the command is not designed to perform this function.
filter(data,rowname >5)
This gives me an error
object 'rowname' not found
For example:
a<-c(1,0,NA,0,1)
b<-c(0,1,1,1,0)
c<-c(1,0,1,0,1)
d<-c(0,NA,1,NA,2)
df<-data.frame(a,b,c,d)
rownames(df) <- c(1:4,"sum_NA")
#filter/select by column
select(df, sum_NA>0)
Desired output:
a d
1 1 0
2 0 NA
3 NA 1
4 0 NA
sum_NA 1 2
If anyone has a workaround or a function designed for this, that would be fantastic.