R-project zoo对象:如何删除数据为非数字的行

我有一个csv文件,其中有两列用逗号分隔 - 第一个是日期,后面是假设为数字数据。 我通过read.csv函数将数据加载到R中,该函数将数据存储在具有2列的data.frame对象中。我执行一些操作将对象转换为动物园对象,索引设置为日期。所以现在对象有一列,假设是数字数据和日期索引。 问题是数据随机分散的字符串“ND”。我想只提取不包含“ND”的动物园对象的那些行。 yr2是动物园关注的对象。 例:
03/15/2011 0.63 
03/16/2011 0.58 
03/17/2011 0.60 
03/18/2011 0.61 
03/21/2011 0.67 
03/22/2011 ND 
03/23/2011 0.69 
03/24/2011 0.72 
03/25/2011 0.79 
03/28/2011 0.81 
03/29/2011 0.81 
03/30/2011 0.80 
03/31/2011 0.80 
我尝试过以下方法:
> yr2[!="ND"]  
Error: unexpected '!=' in "yr2[!="  
> yr2[yr2[!="ND"]]  
Error: unexpected '!=' in "yr2[yr2[!="  
>   
> yr2[!is.character(yr2)]  
Data:  
character(0)  

Index:
Data:
named character(0)

Index:
integer(0)
我非常感谢一些指导。谢谢。     
已邀请:
在将其转换为
zoo
对象之前解决有问题的“ND”数据是否有意义? ND是否代表“无数据”,即应该被解释为NA?
txt <- "03/15/2011 0.63 
03/16/2011 0.58 
03/17/2011 0.60 
03/18/2011 0.61 
03/21/2011 0.67 
03/22/2011 ND 
03/23/2011 0.69 
03/24/2011 0.72 
03/25/2011 0.79 
03/28/2011 0.81 
03/29/2011 0.81 
03/30/2011 0.80 
03/31/2011 0.80"

#If ND == NA
dat <- read.table(textConnection(txt), header = FALSE, na.strings = "ND") 

#if not
dat <- read.table(textConnection(txt), header = FALSE) 

dat[dat$V2 != "ND" ,]

#or

subset(dat, V2 != "ND")
    
试试这个:
Lines <- "03/15/2011 0.63 
03/16/2011 0.58 
03/17/2011 0.60 
03/18/2011 0.61 
03/21/2011 0.67 
03/22/2011 ND 
03/23/2011 0.69 
03/24/2011 0.72 
03/25/2011 0.79 
03/28/2011 0.81 
03/29/2011 0.81 
03/30/2011 0.80 
03/31/2011 0.80"

library(zoo)

z <- read.zoo(textConnection(Lines), format = "%m/%d/%Y", na.strings = "ND")
zz <- na.omit(z)

plot(zz)
    

要回复问题请先登录注册