subsetting

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

subsetting

ANJAN PURKAYASTHA
Hi,
I have a data-frame,  r (column names below), that needs subsetting:
date, time, strain, gene, deltact

When I try to subset r by applying selection criteria on two columns I get
an empty data frame. For example I would like to extract all rows that have
time == 0h and strain == ROC.
So, t <- subset(r, (r$time == "0h" && r$strain == "ROC"), select= c(time,
strain, gene, deltact)) returns an empty data-frame.
Is it not possible to subset based on two criteria?
TIA
Anjan

--
===================================
anjan purkayastha, phd.
research associate
fas center for systems biology,
harvard university
52 oxford street
cambridge ma
phone-703.740.6939
===================================

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: subsetting

Patrick Burns
'&&' is scalar 'and' you want to use
the vector 'and' which is '&'.

On 30/05/2010 16:14, ANJAN PURKAYASTHA wrote:

> Hi,
> I have a data-frame,  r (column names below), that needs subsetting:
> date, time, strain, gene, deltact
>
> When I try to subset r by applying selection criteria on two columns I get
> an empty data frame. For example I would like to extract all rows that have
> time == 0h and strain == ROC.
> So, t<- subset(r, (r$time == "0h"&&  r$strain == "ROC"), select= c(time,
> strain, gene, deltact)) returns an empty data-frame.
> Is it not possible to subset based on two criteria?
> TIA
> Anjan
>

--
Patrick Burns
[hidden email]
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: subsetting

sayan dasgupta
In reply to this post by ANJAN PURKAYASTHA
try
 t <- subset(r, (r$time == "0h" & r$strain == "ROC"), select= c(time,strain, gene, deltact))
Do ?"&" to understand the difference between  & and && .


ANJAN PURKAYASTHA wrote
Hi,
I have a data-frame,  r (column names below), that needs subsetting:
date, time, strain, gene, deltact

When I try to subset r by applying selection criteria on two columns I get
an empty data frame. For example I would like to extract all rows that have
time == 0h and strain == ROC.
So, t <- subset(r, (r$time == "0h" && r$strain == "ROC"), select= c(time,
strain, gene, deltact)) returns an empty data-frame.
Is it not possible to subset based on two criteria?
TIA
Anjan

--
===================================
anjan purkayastha, phd.
research associate
fas center for systems biology,
harvard university
52 oxford street
cambridge ma
phone-703.740.6939
===================================

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: subsetting

David Winsemius
In reply to this post by ANJAN PURKAYASTHA

On May 30, 2010, at 11:14 AM, ANJAN PURKAYASTHA wrote:

> Hi,
> I have a data-frame,  r (column names below), that needs subsetting:
> date, time, strain, gene, deltact
>
> When I try to subset r by applying selection criteria on two columns  
> I get
> an empty data frame. For example I would like to extract all rows  
> that have
> time == 0h and strain == ROC.
> So, t <- subset(r, (r$time == "0h" && r$strain == "ROC"),

At least one error is the use of && instead of &. "&&" will only  
return a single value whereas "&" is the correct operator to use when  
working with vectors.

> select= c(time,
> strain, gene, deltact)) returns an empty data-frame.
> Is it not possible to subset based on two criteria?
> TIA
> Anjan
>
> --
> ===================================
> anjan purkayastha, phd.
> research associate
> fas center for systems biology,
> harvard university
> 52 oxford street
> cambridge ma
> phone-703.740.6939
> ===================================
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> 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.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
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.