[R] transforming a dataset for association analysis
Santosh Srinivas
santosh.srinivas at gmail.com
Sat Oct 30 13:50:10 CEST 2010
A more usable problem input would definitely help ... use dput to send a
reproducible sample to the group
Think the below should solve your problem
> read.csv("Book1.csv")
Subject Item Score
1 Subject 1 Item 1 1
2 Subject 1 Item 2 0
3 Subject 1 Item 3 1
4 Subject 2 Item 1 1
5 Subject 2 Item 2 1
6 Subject 2 Item 3 0
> library("reshape2")
> tDat.m <- melt(tDat)
> tDatCast <- acast(tDat.m,Subject~Item)
> tDatCast
Item 1 Item 2 Item 3
Subject 1 1 0 1
Subject 2 1 1 0
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Ajay Ohri
Sent: 30 October 2010 16:27
To: Rhelp
Subject: [R] transforming a dataset for association analysis
Hi
I would like to transform a data frame like
Subject Item Score
Subject 1 Item 1 1
Subject 1 Item 2 0
Subject 1 Item 3 1
Subject 2 Item 1 1
Subject 2 Item 2 1
Subject 2 Item 3 0
....
*to *
Subject Item1 Item2 Item3 .....Item N
Subject1 1 0 1
Subject2 1 1 0
........
SubjectP..
Apologize for the simple nature of my query but I am stuck. How can I do
this transformation?
Regards
Ajay
Websites-
http://decisionstats.com
http://dudeofdata.com
Linkedin- www.linkedin.com/in/ajayohri
On Sat, Oct 30, 2010 at 2:39 PM, Alaios <alaios at yahoo.com> wrote:
> Hello everyone.
> I have written quite a big function that at the end correctly returns the
> values
> I want. I found a rare exception that I want to cover also. The easier for
> me
> would be to write something like that
>
>
> function(){
>
> if (rare exception happened)
> return that value
>
> # The comes the code for normal execution
> # ...
> # ...
> return value # Normal values to return
>
> }
>
>
>
> Would that be feasible with R or two returns statements are not accepted?
>
> Regards
> Alex
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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]]
______________________________________________
R-help at 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.
More information about the R-help
mailing list