skip NA's when computing dot product

I am adjusting the measurements in a data matrix by subtracting their projections onto the first 1-2 principal components. The problem is, if there is even a single NA in the data matrix (almost inevitable for thousands of measurements), the inner product operation x%*%y (I also tried sum(x*y), for vectors x,y) returns NA. Is there a simple way (i.e. avoiding conditional statements and loops) of computing the inner product on the non-NA values, so that the operation actually returns something?

Incidentally, I would like to avoid just replacing NA's with 0's, since then I would have to renormalize the vectors at each stage.

Answers


You can try this command:

sum(x*y, na.rm = TRUE)

Need Your Help

Taking data from Mysql to JTable in JAVA

java swing jdbc jtable defaulttablemodel

I am trying to have information in my Jtable and reading the info from mysql and it looks like am the era comes from this segment as I can see am stuck , I dont know what to do, Now I have a

How do I publish a Asp.NET web application using MSBuild?

asp.net .net deployment msbuild

I am trying to publish an Asp.net MVC web application locally using the NAnt and MSBuild. This is what I am using for my NAnt target;

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.