I found a solution to this problem myself by searching further and experimenting with some functions.

I ended up with a for-loop which iterates over the cases. It generates a table per case, and selects the most frequent (i.e. the value corresponding with the highest frequency) choice, which  checked to be non-NA and saved to the new variable. I still haven't found a way to re-factor them using the same attributes as the original color-variables... Anyone an idea?

for(i in seq(length(ss$name))) {
	color <- names(which.max(table(c(ss$color1[i], ss$color2[i], ss$color3[i]))))
	
	if(is.null(color))
	{
		ss$color_med[i] <- NA
	}
	else 
	{
		ss$color_med[i] <- as.integer(color)
	}
}


Greetings!
Sam



Op 20-aug-2012, om 10:48 heeft Sam Dekeyser het volgende geschreven:

> Hi,
> 
> I would like to select the most frequent value level in a set of three variables.
> 
> Three different observators have judged hair color in study subjects. Mostly they judge the same color, sometimes there is a slight difference. I want to know what most of the observators have chosen (so at least 2) from the 3 observations. E.g. If two out of three observators decide the hair is black, then it's likely not to be brown.
> 
> Let's say that i have 3 variables: color1, color2, color3. Each have 4 possible levels (fair up to black, 1-4). I would like a new variable containing this 'most frequent judgement'.
> 
> I have already searched through the knowledge base and many posts but I haven't found what I'm looking for.
> 
> Is this possible?
> 
> Thank you in advance!
> Sam
> 
> 
> 


	[[alternative HTML version deleted]]


