[R] Issues reshaping data
John Kane
jrkrideau at yahoo.ca
Thu Jul 22 02:08:52 CEST 2010
A small useable data set would help immensely.
Have a look at ?dput as a way to supply one.
--- On Wed, 7/21/10, JGull8502 <jason.gullifer at gmail.com> wrote:
> From: JGull8502 <jason.gullifer at gmail.com>
> Subject: [R] Issues reshaping data
> To: r-help at r-project.org
> Received: Wednesday, July 21, 2010, 6:05 PM
>
> Hello All,
>
> I'm having some trouble reshaping my data from wide to long
> format. I have
> tried using both the reshape function and package. Although
> I haven't worked
> much with the reshape function, I have found the reshape
> package useful and
> intuitive for reshaping data from long to wide format.
> However, going the
> other way has me stumped with this type of data. My data is
> set up, roughly,
> as follows:
>
> SUBJECT TRIAL WORD1
> WORD1.RT
> WORD2
> WORD2.RT ...
>
> WORD25.RT
> 1
> 1 My
> 100
> friend
> 200
>
> ...
> ...
> 1
> 2 John's
> 250
> dog
> 320
>
> ...
> ...
> 1
> 3 His
> 120
> waiter
> 400
> ...
> ...
> 2
> 1 My
> 100
> friend
> 200
> ...
> ...
> 2
> 2 John's
> 250
> dog
> 320
>
> ...
> ...
> 2
> 3 His
> 120
> waiter
> 400
> ...
> ...
>
> What I would like to do is transform it roughly to:
>
> Subject TRIAL
> WORD RT
> 1
> 1
> My 100
> 1
> 1
> friend 200
> ....
> ....
> ..... ....
> 2
> 3
> His 120
> 2
> 3
> Waiter 400
>
> The furthest I've gotten with the package is melting the
> data such that RT
> is in its own column by using each WORD#.RT as a
> measure.var. However, I
> can't get the words to go with them (either in the melted
> frame or trying to
> cast the melted data).
>
> I tried the reshape function as well, but kept getting an
> error about
> duplicate row names. I lost the exact code I was using
> after closing R, but
> roughly, I would use Subject as an ID variable, varying =
> list(wordRTs,words) [where wordRTs are the set of WORD#.RT
> and words are the
> set of WORD# columns] , v.names=c("RT","WORD").
>
> If anyone has any help, it would be much appreciated!
>
> Thanks,
> Jason
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Issues-reshaping-data-tp2297853p2297853.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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