I am trying to repeat plotting in R my main command is
data<-read.csv(file.choose(),header=TRUE)
t=data[,1]
PCI=data[,2]
plot(t,PCI,xlim=c(0,30))
boxplot(t,PCI,xlim=c(0,30))
# some starting values
alpha=1
betha=1
theta=1
# do the fit
fit = nls(ydata ~ alpha-beta*exp((-theta*(xdata^gama))), start=list(alpha=80,beta=15,theta=15,gama=-2))
ydata=data[,2]
xdata=data[,1]
new = data.frame(xdata = seq(min(xdata),max(xdata),len=200))
lines(new$xdata,predict(fit,newdata=new))
resid(fit)
qqnorm(resid(fit))
fitted(fit)
resid(fit)
xdata=fitted(fit)
ydata=resid(fit)
plot(xdata,ydata,xlab="fitted values",ylab="Residuals")
abline(0, 0)
My first column is number of section, my second column is t=x and my third column is PCI=y. I want to repeat my plotting command for each section individually.but I think I can not use loop since the number of data in each section is not equal. I would really appreciate your help since i am new in R.
SecNum t PCI
961 1 94.84
961 2 93.04
961 3 91.69
961 11 80.47
961 12 79.26
961 13 77
962 1 90.46
962 2 90.01
962 3 86.88
962 4 86.36
962 5 84.56
962 6 85.11
963 1 91.33
963 2 90.7
963 3 86.46
963 4 88.47
963 5 81.07
963 6 84.07
963 7 82.55
963 8 73.58
963 9 71.85
963 10 83.8
963 11 82.16