Skip to content

Remove part of string in colname and calculate mean for columns groups

2 messages · Joel Fürstenberg-Hägg, Dieter Menne

#
Joel F?rstenberg-H?gg wrote:
If you do that in the example you gave, duplicate column names would be the
result, but let's assume that was a typo.

# Simplify names
data = data.frame(Akita.0_ACC1=1:2,Akita.1_ACC2=2:3,Alc.0_ACC1=3:4)
names(data) = sub("_.*","",names(data))
# Make a new data frame with the Akitas only
dataAkita = data[,grep("Akita",names(data))]

To do the averaging, check the examples in package plyr. 

Dieter