我有想貓不同的字符串來使用,如果在不同的條件文件 - else語句:[R語法問題
cat("<graph caption=\"ECG Data Wave\" subcaption=\"For Person's Name\" xAxisName=\"Time\" yAxisMinValue=\"-0.025\" yAxisName=\"Voltage\" decimalPrecision=\"5\" formatNumberScale=\"0\" numberPrefix=\"\" showNames=\"1\" showValues=\"0\" showAlternateHGridColor=\"1\" AlternateHGridColor=\"ff5904\" divLineColor=\"ff5904\" divLineAlpha=\"20\" alternateHGridAlpha=\"5\">\n")
if (df$BP > 140 && df$Yvoltage < -0.05){
cat(sprintf(" <set name=\"%s\" value=\"%f\" hoverText = \"Blood Pressure High, Level of Activity Low\" ></set>\n", df$XTimeStamp, df$YVoltage, diff))else
if (df$BP > 140 && df$Yvoltage > -0.05)
cat(sprintf(" <set name=\"%s\" value=\"%f\" hoverText = \"Blood Pressure Normal, Level of Activity Normal\" ></set>\n", df$XTimeStamp, df$YVoltage, diff)) else
if (df$BP > 140 && df$Yvoltage > -0.35)
cat(sprintf(" <set name=\"%s\" value=\"%f\" hoverText = \"Blood Pressure High, Level of Activity High\" ></set>\n", df$XTimeStamp, df$YVoltage, diff))}
cat(' <trendlines>
<line startvalue="0.30" displayValue="High Activity" color="FF0000" thickness="1" isTrendZone="0"></line>
<line startvalue="-0.05" displayValue="Low Activity" color="009999" thickness="1" isTrendZone="0"></line>
\ n「) 貓( 」\ n「)
當我試圖運行我不斷收到錯誤的代碼,如下所示:
Error: unexpected 'else' in:
"if (df$BP > 140 && df$Yvoltage < -0.05){
cat(sprintf(" <set name=\"%s\" value=\"%f\" hoverText = \"Blood Pressure High, Level of Activity Low\" ></set>\n", df$XTimeStamp, df$YVoltage, diff))else"
任何想法,我哪裏會出錯?這是否正確,這是否有更好的方法來編寫文件?
我正在嘗試關注Spacedman的建議並使用brew。我曾嘗試它不同的差異和我要麼收到以下錯誤信息:
Error: unexpected input in "cat (sprintf(" <set name=\"%s\" value=\"%f\" hoverText = "<%= hovertext =>" ></set>\n", df$XTimeStamp, df$YVoltage))"
,或者如果我得到它的工作hovertext保持不變,整個一路下滑。
目前將R代碼如下:
if(df$BP > 140 && df$YVoltage < -0.05){
hovertext ="Blood Pressure High, Level of Activity Low"
}else{
if(df$BP < 140 && df$BP > 90 && df$YVoltage > -0.05 && df$YVoltage < 0.30){
hovertext ="Blood Pressure normal, Level of Activity normal"
} else {
hovertext ="Blood Pressure High, Level of Activity high"
}
sink (file="c:/Users/usr/Desktop/data.xml", type="output",split=FALSE)
cat("<graph caption=\"ECG Data Wave\" subcaption=\"For Person's Name\" xAxisName=\"Time\" yAxisMinValue=\"-0.025\" yAxisName=\"Voltage\" decimalPrecision=\"5\" formatNumberScale=\"0\" numberPrefix=\"\" showNames=\"1\" showValues=\"0\" showAlternateHGridColor=\"1\" AlternateHGridColor=\"ff5904\" divLineColor=\"ff5904\" divLineAlpha=\"20\" alternateHGridAlpha=\"5\">\n")
cat(sprintf(" <set name=\"%s\" value=\"%f\" hoverText = "<%= hovertext =>" ></set>\n", df$XTimeStamp, df$YVoltage))
cat(' <trendlines>
<line startvalue="0.30" displayValue="High Activity" color="FF0000" thickness="1" isTrendZone="0"></line>
<line startvalue="-0.05" displayValue="Low Activity" color="009999" thickness="1" isTrendZone="0"></line>
</trendlines>\n')
cat ("</graph>\n")
unlink("data.xml")
在哪裏我仍然在代碼中走錯了任何的想法?
您似乎沒有指定要寫入的文件,只會打印出原樣。 – James 2010-09-02 09:23:07