简体   繁体   中英

R create a function to plot and do a regression for several rows of a data set

i am new to programming / R and i have a question that might be very easy.

my function is:

par(mfrow=c(2,2))    
plot_QQ=function(x) {for(i in 2:x)
     plot(c(data_raw[,Group1[i]]),c(data_raw[,Group1[1]]), xlab=paste("replicate",i), ylab="replicate 1")
           abline(lm(c(data_raw[,Group1[i]])c(data_raw[,Group1[1]]))}

group1 is an vector c("","","") to grap specific the data. This function is working, but R does not draw the abline() in all plots. (only in the "last" plot c(data_raw[,Group1[i=x]]),c(data_raw[,Group1[1]]) the line is drawn.

sorry for such an easy question and thx for helping

greetz

In future you should supply some simulated data so that people can run your code, it's unclear what exactly you're trying to do. You don't need the c() functions, and your lm call isn't proper. Also you don't have curly braces around your for loop. Try this.

par(mfrow=c(2,2))    
    plot_QQ=function(x) {for(i in 2:x){
    plot(data_raw[,Group1[i]],data_raw[,Group1[1]], xlab=paste("replicate",i), ylab="replicate 1")
    abline(lm(data_raw[,Group1[i]]~data_raw[,Group1[1]])}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM