Hi, I would like to use the R's outer function on y below so that I can subtract elements from each other. The resulting dataframe is symmetric, save for the negative signs on the other half of the numbers. I would like to get only half of the dataframe. Here is the code I wrote (it is returning only the first line of the all elements I want. Please help). y<-c(4,4,3.9,3.8,3.7,3.6,3.5,3.5,3.5,3.3,3.2,3.2)
b<-outer(y,y,"-") b<-as.matrix(by) # I want to keep the elements: #b[1,2:12], #b[2,3:12], #.........until #b[11,12:12]. #Here is the function I wrote to get half of matrix: wk<-function(p){ for (i in 2:p){ ri<-b[i-1,i:p] return(ri) } } wk(12) #[1] 0.0 0.1 0.2 0.3 0.4 0.5 0.5 0.5 0.7 0.8 0.8 As you can see, it is only returning the first line. I would like other corresponding elements too, to be found in row 2 to 12. Thanks. -- View this message in context: http://www.nabble.com/help-using-outer-function-tp18914432p18914432.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.