[R] Find NA in xts object

2013-03-16 Thread Pete
Hi to all, i'm new to R

I have an xts object.
Can i find:
a) how many NA are in my object ?
b) eventually where (in which line) they are 

Thank you

__
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.


Re: [R] Find NA in xts object

2013-03-16 Thread Joshua Ulrich
On Sat, Mar 16, 2013 at 2:25 PM, Pete freeri...@gmail.com wrote:
 Hi to all, i'm new to R

 I have an xts object.
 Can i find:
 a) how many NA are in my object ?

sum(is.na(obj))

 b) eventually where (in which line) they are

which(is.na(obj))

 Thank you


Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

R/Finance 2013: Applied Finance with R  | www.RinFinance.com

__
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.


Re: [R] Find NA in xts object

2013-03-16 Thread arun
HI,
Try this:
 Date1- seq(as.Date(2012-09-10,format=%Y-%m-%d),length.out=20,by=day)
set.seed(25)
value- sample(c(1:5,NA),20,replace=TRUE)
library(xts)
x1- xts(value,Date1)
colSums(is.na(x1))
#[1] 3
 which(is.na(x1))
#[1]  4  6 13

set.seed(38)
 value2- sample(c(5:8,NA),20,replace=TRUE)
 x2- xts(cbind(value,value2),Date1)
colSums(is.na(x2))
# value value2 
 #    3  2 
sapply(x2,function(y) which(is.na(y)))
#$value
#[1]  4  6 13

#$value2
#[1] 10 17
A.K.





- Original Message -
From: Pete freeri...@gmail.com
To: r-h...@stat.math.ethz.ch
Cc: 
Sent: Saturday, March 16, 2013 3:25 PM
Subject: [R] Find NA in xts object

Hi to all, i'm new to R

I have an xts object.
Can i find:
a) how many NA are in my object ?
b) eventually where (in which line) they are 

Thank you

__
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.


__
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.