[R] selecting the COLUMNS in a dataframe function of the numerical values in a ROW
William Dunlap
wdun|@p @end|ng |rom t|bco@com
Fri Nov 2 02:08:20 CET 2018
This would be a bit simpler if 'gene' were the rownames of the data.frame.
The '-4' is to remove the gene column from the calculations.
> x[ x[,"gene"]=="gene2",]
TTT TTA ATA gene
2 1 1 0 gene2
> colnames(x)[-4][ 1 == x[ x[,"gene"]=="gene2",-4] ]
[1] "TTT" "TTA"
> colnames(x)[-4][ 1 == x[ x[,"gene"]=="gene3",-4] ]
[1] "TTA"
> x
TTT TTA ATA gene
1 0 0 1 gene1
2 1 1 0 gene2
3 0 1 0 gene3
4 0 0 0 gene4
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Thu, Nov 1, 2018 at 5:45 PM, Bogdan Tanasa <tanasa using gmail.com> wrote:
> Dear all, please may I ask for a suggestion :
>
> considering a dataframe that contains the numerical values for gene
> expression, for example :
>
> x = data.frame(TTT=c(0,1,0,0),
> TTA=c(0,1,1,0),
> ATA=c(1,0,0,0),
> gene=c("gene1", "gene2", "gene3", "gene4"))
>
> how could I select only the COLUMNS where the value of a GENE (a ROW) is
> non-zero ?
>
> thank you !
>
> -- bogdan
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list