Displaying 1 result from an estimated 1 matches for "rowtrait".
Did you mean:
rowtraits
2010 Jan 29
1
apply function with grouped columns
...have been doing is below.
#Four observations of four variables
v1 <- c(1, 8, 5, 3)
v2 <- c(5, 5, 6, 5)
v3 <- c(3, 2, 9, 4)
v4 <- c(4, 1, 1, 1)
myData <- data.frame(v1=v1, v2=v2, v3=v3, v4=v4)
myData
#The observations have either property 1 or property 2
rowFactor <- data.frame(RowTraits=factor(c(1, 2, 1, 2)))
rowFactor
#The variables have a property that is either present or absent
colFactor <- data.frame(ColTraits=factor(c(1, 1, 0, 0)))
colFactor
#Getting the means for the columns by row groups is easy
MeanByRowTraits <- aggregate (myData, rowFactor[1], mean)
MeanByRowTr...