[R] error in a abline loop

Pascal Oettli kridox at ymail.com
Tue Jan 8 03:30:50 CET 2013


Hi,

Now, you have too many ")" in the code. The last line should be (as 
written in the code I sent you):

 > abline(line,col=c("yellow","chocolate1","darkorange2",
 > "red3","saddlebrown","coral4","grey38")[i],lwd=2)

HTH,
Pascal


Le 08/01/2013 11:24, Elaine Kuo a écrit :
> Hello
>
> Thanks.
> It is right a ) is missing for lm.
> With the modification, I ran the code but the command seems not
> closed, with + instead of >.
> Please kindly help.
>
> The code modified
> for (i in 1:7) {
>      subs <- data$skin_color==levels(data$skin_color)[i]
>      line<-lm(body_weight~body_length, data=subset(data, subset=subs))
>      abline(line,col=c("yellow","chocolate1","darkorange2",
> "red3","saddlebrown","coral4","grey38")[i],lwd=2) )
>      }
>
> Elaine
>
>
>
> On Tue, Jan 8, 2013 at 10:03 AM, arun <smartpink111 at yahoo.com> wrote:
>>
>> HI,
>>
>> A possible guess ( with no data):
>> for (i in 1:7) {
>>      subs <- data$skin_color==levels(data$skin_color)[i]
>>      line<-lm(body_weight~body_length, data=subset(data, subset=subs)) #closing parentheses
>>      abline(line,col=c("yellow","chocolate1","darkorange2",
>> "red3","saddlebrown","coral4","grey38")[i],lwd=2)
>>      }
>>
>>
>> A.K.
>>
>>
>>
>> ----- Original Message -----
>> From: Elaine Kuo <elaine.kuo.tw at gmail.com>
>> To: r-help at r-project.org
>> Cc:
>> Sent: Monday, January 7, 2013 8:23 PM
>> Subject: [R] error in a abline loop
>>
>> Hello
>>
>> I have data of body length and body weight of people of different skin colors.
>>
>> I tried to write a code to plot body length and body weight according
>> to the skin colors.
>> (Thanks for Petr's advice so far.)
>>
>> A loop is used but an error shows up in the following code.
>> It says:
>> unexpected '}' in
>> "    "red3","red3","saddlebrown","coral4","chocolate4","darkblue","navy","grey38")[i],lwd=2)
>>      }"
>>
>> Please kindly advise how to modify the code.
>> Thank you.
>>
>> The code
>>    data <-read.csv("H:/skincolor.csv",header=T)
>>
>>    # graph
>>      par(mai=c(1.03,1.03,0.4,0.4))
>>
>>      plot(data$body_weight, data$body_length,
>>      xaxp=c(0,200,4),
>>      yaxp=c(0,200,4),
>>      type="p",
>>      pch=1,lwd=1.0,
>>      cex.lab=1.4, cex.axis=1.2,
>>      font.axis=2,
>>      cex=1.5,
>>      las=1,
>>      bty="l",col=c("yellow","chocolate1","darkorange2",
>> "red3","saddlebrown","coral4","grey38")[as.numeric(data$skin_color)])
>>
>>
>>      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>      ##
>>      for (i in 1:7) {
>>      subs <- data$skin_color==levels(data$skin_color)[i]
>>      line<-lm(body_weight~body_length, data=subset(data, subset=subs),
>>      abline(line,col=c("yellow","chocolate1","darkorange2",
>> "red3","saddlebrown","coral4","grey38")[i],lwd=2)
>>      }
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list