[R] build matrix with the content of one column of a data frame in function of two factors

VinceD vincent.degove at laposte.net
Wed Jul 9 18:59:30 CEST 2008


Seems that the following makes what I want :

attach(votesredac)
tapply(value, list(name, content_id), mean)

Only thing is, I don't need to make a mean - there is only one or no value.



VinceD wrote:
> 
> Hello,
> 
> First, thanks for your help (and sorry for my english !)
> 
> I have a data frame in which each row represents a vote (in percent, only
> 20,40, 60,80,100) of one person on one content, with three columns : name
> (the name of the voters), content_id, vote :
> 
> str(votesredac)
> 'data.frame':	1000 obs. of  3 variables:
>  $ name      : chr  "Guillemette Faure" "Guillemette Faure" "Guillemette
> Faure" "Pascal Rich\xe9" ...
>  $ content_id: num  385241 384926 384635 383266 384814 ...
>  $ value     : num  100 100 100 20 100 100 20 100 100 100 ...
> 
> I want to build a matrix with one column for each content and one line for
> each user, containing the votes. This matrix can content NAs (each person
> hasn't voted on all contents). If each row and column was labelled, would
> be better.
> 
> 
> Thanks again !
> 

-- 
View this message in context: http://www.nabble.com/build-matrix-with-the-content-of-one-column-of-a-data-frame-in-function-of-two-factors-tp18364752p18366233.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list