Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

How to go about finding the slope of a series of observations, with different N in each row?

$
0
0

I have a dataframe that looks like this, where each observation is the size of a school's enrollment:

          Year1    Year2    Year3    Year4    Year5    Year6    Year7   Slope
School1    89       87       74        64      0         0       0   
School2    100      99       90        87      83        80      0   
School3    65       30       0         0       0         0       0   

I'm trying to calculate the slope of enrollment declines in the year leading up to the closure of the school, with the output ending up in the "slope" column.

More generally, I'm trying to calculate the slope of a series of observations up until the first "stop" value (in this case, zero).

Thanks in advance!


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>