Skip to content
Prev 163908 / 398506 Next

adding rows as arithmatic calculation on original rows

This should get you close:
+ a       Single       10          11           12
+ b       Single       15          25           35
+ c       Double      22          33           44
+ d       Double        4           6             8"), header=TRUE)
+     .means <- colMeans(.type[,3:5])
+     # create the new line for the data frame
+     .df <- data.frame(myID='', myType=.type$myType[1], myNum1=.means[1],
+         myNum2=.means[2], myNum3=.means[3])
+     rbind(.type, .df) # append the line to the original dataframe
+ })
myID myType myNum1 myNum2 myNum3
Double.3         c Double   22.0   33.0   44.0
Double.4         d Double    4.0    6.0    8.0
Double.myNum1      Double   13.0   19.5   26.0
Single.1         a Single   10.0   11.0   12.0
Single.2         b Single   15.0   25.0   35.0
Single.myNum1      Single   12.5   18.0   23.5
On Fri, Dec 5, 2008 at 3:21 PM, Ferry <fmi.mlist at gmail.com> wrote: