[R] error in density plot

Ben Bolker bbolker at gmail.com
Wed Feb 2 14:22:25 CET 2011


Ramya <ramya.victory <at> gmail.com> writes:

> I have the code for the density plot
> j <- 8 
> plot(density(diff_in_sample[,1]), main = list.files()[j])
> for(i in 1:25){
> lines(density(diff_in_sample[,i]))
> }
> 
> This gives me an error 
> Error in density.default(diff_in_sample[, i]) : 
>   'x' contains missing values

 [snip]

?NA

lines(na.omit(density(diff_in_sample[,i])))

Consider replacing the loop by apply() [no efficiency
gain, but more compact code]



More information about the R-help mailing list