1 Dec 17:32
Re: Error: "subscript out of bounds"
From: <Jagat.K.Sheth <at> wellsfargo.com>
Subject: Re: Error: "subscript out of bounds"
Newsgroups: gmane.comp.lang.r.general
Date: 2008-12-01 16:32:34 GMT
Subject: Re: Error: "subscript out of bounds"
Newsgroups: gmane.comp.lang.r.general
Date: 2008-12-01 16:32:34 GMT
Note that length(m) = 16, but your m is only 4x4.
Try this m[is.na(m)] <- 0
-----Original Message-----
From: r-help-bounces <at> r-project.org [mailto:r-help-bounces <at> r-project.org]
On Behalf Of Alex99
Sent: Monday, December 01, 2008 9:06 AM
To: r-help <at> r-project.org
Subject: [R] Error: "subscript out of bounds"
Hi All,
I am trying to replace the "NA" values in a matrix by using the
following
function:
it gets a "name" of the matrix or list or vector and turns it to a
matrix called "m".
then checks the elements of the matrix and if any of them is "NA"
replace them with "0".
rep=function(name){
m=as.matrix(name)
for(i in 1:length(m)){
for(j in 1:length(m)){
if(is.na(m[i,j])){
m[i,j]=0
}}}}
when I use the function with the following matrix:
(Continue reading)
RSS Feed