[R] error in lm.fit

Martin Wegmann mailinglist.wegmann at gmx.net
Thu Sep 4 18:20:52 CEST 2003


Hello R user, 

I have several data frames with >100 columns and I did a linear regression 
over time of each column

df1.lm <- lapply(df1, function(x) lm(x~year)$coeff[2])

that worked fine and I get slope of each column oder time - until I divided 
df1 by df2 

df3 <- df1/df2

> df3.lm <- lapply(df3, function(x) lm(x~year)$coeff[2])
Error in lm.fit(x, y, offset = offset, ...) :
        0 (non-NA) cases

df3 has cases:
      X106      X107      X108
1  -2.200986 -2.128744 -2.126991
2  -2.201284 -2.179806 -1.998352
3  -2.201589 -2.051754 -1.918321
4  -2.207428 -2.024579 -2.160275
5  -2.088381 -2.084716 -2.033241
6  -2.313741 -1.905484 -2.024190
7  -2.232551 -2.118113 -2.123781
8  -2.096430 -1.787569 -2.309956
9  -2.029564 -1.650830 -2.038038
10 -1.805616 -1.936357 -1.827615
11 -2.427711 -2.260115 -2.192925
12 -2.255148 -1.624925 -2.075030
13 -2.040811 -1.928457 -1.985597
14 -2.131254 -2.126999 -2.079338
15 -2.407123 -2.193653 -2.162101
16 -2.024426 -2.168195 -2.078530
17 -2.224164 -1.853840 -2.150593
18 -2.067553 -2.140541 -1.907311
19 -2.142151 -2.176615 -2.015018
20 -2.125215 -2.051265 -1.848539

I did it with df1 and df2, both worked, the only difference I recognized so 
far were the negative values and the amount of decimal places, therefore I 
added 10 and multiplied it with 1000000 but both approaches didn't work. 

any idea what I might have done wrong?

(using R 1.7.0  Linux)

thanks, Martin




More information about the R-help mailing list