Quantcast

Not able to filter factor, class

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Not able to filter factor, class

Sri krishna Devarayalu Balanagu
After importing data from Excel through ODBC.
In the inclusion dataset, class(inclusion$Value) is coming as factor. After filtering the data, length(inclusion$Value == 0),the answer is coming as 4879, but actually Value contains only 225 rows. So how can I get the length as 225.
Can anyone help?

setwd("D:/AZ")
library("RODBC")
cdb_cnct <- odbcConnectExcel("AZIF_DC_GVK_NSCLC_MSALL_287papers_02072012_141450_v1_4.xls")
arm <- sqlFetch(cdb_cnct, "Arm")
inclusion <- sqlFetch(cdb_cnct, "Inclusion")
odbcClose(cdb_cnct)
rm(cdb_cnct)
names(inclusion)
[1] "Trial_Design_ID"    "Reference_ID"       "Inclusion_Criteria"
[4] "Value"              "F5"                 "F6"
> class(inclusion$Value)
[1] "factor"

> nrow(inclusion)
[1] 4879
> length(inclusion$Value == 0)
[1] 4879
> length(inclusion$Value == "0")
[1] 4879
________________________________
Notice: The information contained in this electronic mail message is intended only for the use of the designated recipient. This message is privileged and confidential. and the property of GVK BIO or its affiliates and subsidiaries. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone +91-40-66929999<tel:%2B91-40-66929999> and destroy any and all copies of this message in your possession (whether hard copies or electronically stored copies).

        [[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
|  
Report Content as Inappropriate
star

Re: Not able to filter factor, class

John Kane
Are you sure that you are not confusing the number of levels with the length of the vector?

John Kane
Kingston ON Canada


> -----Original Message-----
> From: [hidden email]
> Sent: Tue, 14 Aug 2012 12:40:26 +0000
> To: [hidden email]
> Subject: [R] Not able to filter factor, class
>
> After importing data from Excel through ODBC.
> In the inclusion dataset, class(inclusion$Value) is coming as factor.
> After filtering the data, length(inclusion$Value == 0),the answer is
> coming as 4879, but actually Value contains only 225 rows. So how can I
> get the length as 225.
> Can anyone help?
>
> setwd("D:/AZ")
> library("RODBC")
> cdb_cnct <-
> odbcConnectExcel("AZIF_DC_GVK_NSCLC_MSALL_287papers_02072012_141450_v1_4.xls")
> arm <- sqlFetch(cdb_cnct, "Arm")
> inclusion <- sqlFetch(cdb_cnct, "Inclusion")
> odbcClose(cdb_cnct)
> rm(cdb_cnct)
> names(inclusion)
> [1] "Trial_Design_ID"    "Reference_ID"       "Inclusion_Criteria"
> [4] "Value"              "F5"                 "F6"
>> class(inclusion$Value)
> [1] "factor"
>
>> nrow(inclusion)
> [1] 4879
>> length(inclusion$Value == 0)
> [1] 4879
>> length(inclusion$Value == "0")
> [1] 4879
> ________________________________
> Notice: The information contained in this electronic mail message is
> intended only for the use of the designated recipient. This message is
> privileged and confidential. and the property of GVK BIO or its
> affiliates and subsidiaries. If the reader of this message is not the
> intended recipient or an agent responsible for delivering it to the
> intended recipient, you are hereby notified that you have received this
> message in error and that any review, dissemination, distribution, or
> copying of this message is strictly prohibited. If you have received this
> communication in error, please notify us immediately by telephone
> +91-40-66929999<tel:%2B91-40-66929999> and destroy any and all copies of
> this message in your possession (whether hard copies or electronically
> stored copies).
>
> [[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.

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

______________________________________________
[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
|  
Report Content as Inappropriate
star

Re: Not able to filter factor, class

nalluri pratap
I agree with John. Can you check that?
 
length(which(inclusion$Value == 0))

Pratap

--- On Wed, 15/8/12, John Kane <[hidden email]> wrote:


From: John Kane <[hidden email]>
Subject: Re: [R] Not able to filter factor, class
To: "Sri krishna Devarayalu Balanagu" <[hidden email]>, "[hidden email]" <[hidden email]>
Date: Wednesday, 15 August, 2012, 12:37 AM


Are you sure that you are not confusing the number of levels with the length of the vector?

John Kane
Kingston ON Canada


> -----Original Message-----
> From: [hidden email]
> Sent: Tue, 14 Aug 2012 12:40:26 +0000
> To: [hidden email]
> Subject: [R] Not able to filter factor, class
>
> After importing data from Excel through ODBC.
> In the inclusion dataset, class(inclusion$Value) is coming as factor.
> After filtering the data, length(inclusion$Value == 0),the answer is
> coming as 4879, but actually Value contains only 225 rows. So how can I
> get the length as 225.
> Can anyone help?
>
> setwd("D:/AZ")
> library("RODBC")
> cdb_cnct <-
> odbcConnectExcel("AZIF_DC_GVK_NSCLC_MSALL_287papers_02072012_141450_v1_4.xls")
> arm <- sqlFetch(cdb_cnct, "Arm")
> inclusion <- sqlFetch(cdb_cnct, "Inclusion")
> odbcClose(cdb_cnct)
> rm(cdb_cnct)
> names(inclusion)
> [1] "Trial_Design_ID"    "Reference_ID"       "Inclusion_Criteria"
> [4] "Value"              "F5"                 "F6"
>> class(inclusion$Value)
> [1] "factor"
>
>> nrow(inclusion)
> [1] 4879
>> length(inclusion$Value == 0)
> [1] 4879
>> length(inclusion$Value == "0")
> [1] 4879
> ________________________________
> Notice: The information contained in this electronic mail message is
> intended only for the use of the designated recipient. This message is
> privileged and confidential. and the property of GVK BIO or its
> affiliates and subsidiaries. If the reader of this message is not the
> intended recipient or an agent responsible for delivering it to the
> intended recipient, you are hereby notified that you have received this
> message in error and that any review, dissemination, distribution, or
> copying of this message is strictly prohibited. If you have received this
> communication in error, please notify us immediately by telephone
> +91-40-66929999<tel:%2B91-40-66929999> and destroy any and all copies of
> this message in your possession (whether hard copies or electronically
> stored copies).
>
>     [[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.
____________________________________________________________
[[elided Yahoo spam]]

______________________________________________
[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.

        [[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
|  
Report Content as Inappropriate
star

Re: Not able to filter factor, class

PIKAL Petr
In reply to this post by Sri krishna Devarayalu Balanagu
Hi

>
> After importing data from Excel through ODBC.
> In the inclusion dataset, class(inclusion$Value) is coming as factor.
> After filtering the data, length(inclusion$Value == 0),the answer is
> coming as 4879, but actually Value contains only 225 rows. So how can I

How do you know?
What does
str(inclusion) and
dim(inclusion)

says about your data.


> get the length as 225.
> Can anyone help?
>
> setwd("D:/AZ")
> library("RODBC")
> cdb_cnct <-
> odbcConnectExcel("AZIF_DC_GVK_NSCLC_MSALL_287papers_02072012_141450_v1_
> 4.xls")
> arm <- sqlFetch(cdb_cnct, "Arm")
> inclusion <- sqlFetch(cdb_cnct, "Inclusion")
> odbcClose(cdb_cnct)
> rm(cdb_cnct)
> names(inclusion)
> [1] "Trial_Design_ID"    "Reference_ID"       "Inclusion_Criteria"
> [4] "Value"              "F5"                 "F6"
> > class(inclusion$Value)
> [1] "factor"
>
> > nrow(inclusion)
> [1] 4879
> > length(inclusion$Value == 0)
> [1] 4879
> > length(inclusion$Value == "0")
> [1] 4879

Any from the above gives you logical vector with same length as inclusion$Value. If you want only TRUE values use ?subset or ?"[" to select those values.

Regards
Petr

> ________________________________
> Notice: The information contained in this electronic mail message is
> intended only for the use of the designated recipient. This message is
> privileged and confidential. and the property of GVK BIO or its
> affiliates and subsidiaries. If the reader of this message is not the
> intended recipient or an agent responsible for delivering it to the
> intended recipient, you are hereby notified that you have received this
> message in error and that any review, dissemination, distribution, or
> copying of this message is strictly prohibited. If you have received
> this communication in error, please notify us immediately by telephone
> +91-40-66929999<tel:%2B91-40-66929999> and destroy any and all copies
> of this message in your possession (whether hard copies or
> electronically stored copies).
>
> [[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.

______________________________________________
[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.
Loading...