[R] Not able to filter factor, class

PIKAL Petr petr.pikal at precheza.cz
Thu Aug 16 15:19:42 CEST 2012


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]]
> 
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list