Apologies if this doesn't make any sense, this is my first experience using R (and coding in general) and I'm lost. Any help would be greatly appreciated.
I have a data set of case numbers from various countries and years for measles.
So far, I have (I'm assuming correctly but am not completely sure):
subsetted that data set to only contain info for after 1998 (to 2018), called All_after
using a loop (1-194 being the different countries), run a linear model of the effect of year on the natural log during this time period
What I should have is slope for each country from the linear model (which I can then plot as histograms). However, with my current code I am 'slope-less'. I've tried abline functions and lm functions inside and outside the loop but get the answer that whatever I put in the brackets isn't finite.
Here's my code so far:
All_after <- subset(Measles, year >= 1998, year < 2018)
attach(All_after)
All_after$Cname <- "1":"194"
log_All_after <- log(All_after[,7]+1)
i <- c(Cname="1":"194")
for (val in i) {
with(All_after[All_after$Cname==1,] plot(year,log_All_after))
model5 <- lm(log_All_after~year, data=All_after, subset=i)
}
Again, apologies if this is all gibberish!
Edit:
Using the summary function, this is what appears for All_after :
> summary(All_after)
X WHO_REGION ISO_CODE Cname
Min. :3493 AFR : 987 AFG : 21 Afghanistan : 21
1st Qu.:4511 AMR : 735 AGO : 21 Albania : 21
Median :5530 EMR : 441 ALB : 21 Algeria : 21
Mean :5530 EUR :1113 AND : 21 Andorra : 21
3rd Qu.:6548 SEAR: 231 ARE : 21 Angola : 21
Max. :7566 WPR : 567 ARG : 21 Antigua and Barbuda: 21
(Other):3948 (Other) :3948
Disease year cases
measles:4074 Min. :1998 Min. : 0.0
1st Qu.:2003 1st Qu.: 0.0
Median :2008 Median : 20.5
Mean :2008 Mean : 2402.6
3rd Qu.:2013 3rd Qu.: 446.5
Max. :2018 Max. :217151.0
NA's :294