[R] Odp: Newbie question: Converting Table
petr.pikal at precheza.cz
Fri Sep 23 14:10:00 CEST 2011
> [R] Newbie question: Converting Table
> I'm new to R, and I have searched helpfiles and this forum on my 2
> questions. Hope you guys can help me out! :-)
You did not search enough. You probably want table or xtabs
res <- xtabs(~subject+class, data=your.file)
ifelse(res==1, "yes", "no")
I do not understand what exactly do you want. Please be more specific.
BTW, if you are in it you'd rather give a look to posting guide.
> Many thanks in advance!
> Q1: I imported a csv file with columnames subject and class. There are
> 1000 different classes...
> It looks like this:
> subject1, class1
> subject1, class2
> subject2, class1
> subject2, class3
> subject999, class1
> subject999, class2
> Now I want to transform this in R into a table (with columnnames
> subject,class1,class2,...) like:
> subject1, yes, yes, no, ...
> subject2, yes, no, yes, ...
> Q2: I want to count the matching class patterns in the previous table
> (output: in a table with columns count, class1, ...). In this example
> only the subjects1,2 and 999 it looks like this:
> View this message in context: http://r.789695.n4.nabble.com/Newbie-
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help