Dear Leon,
It's not the most efficient way but it works. Hopefully someone else will
come up with another approach. Here a toy example: 1. calculate the mean for
each name in your second column by using tapply or others, 2. determinate
which names are repeated >= 2 times, 3. match the names of the mean you
estimated in number 1 with the names in number 2 and 4. extract the
elements:

# Data set
set.seed(123)
mydata=data.frame(value=rnorm(6), Names= c("yes", "no", "yes", "yes", "no",
"not sure"))

# mean
Mean=tapply(mydata$value,mydata$Names,mean)

# which names have frequencies >= 2 and match
index=names(Mean)%in%names(table(mydata$Names))[table(mydata$Names)>=2]

# extracting the elements
Mean[index]
 no         yes
-0.05044488  0.35624702

HTH,

Jorge


On Wed, Oct 29, 2008 at 10:19 AM, Leon Yee <yee.leon@gmail.com> wrote:

>
> Gustaf Rydevik wrote:
>
>> Hi Leon,
>>
>> unique(x)
>>
>> or
>>
>> duplicated(x)
>>
>> should work, depending on what you want.
>>
>> Best,
>>
>> Gustaf
>>
>>
> Hi,
>   Thank you all. Actually, I have a data frame or matrix, whose first
> column is numerical values, and whose 2nd column is names. I need those
> whose names repeated 3 times and get the mean of the 3 values for each
> repeated names.
>
>   It sounds that I need some programming work.
>
> Regards,
> Leon
>
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]

