[R] Transform values from one column into column names of new dataframe

2008-05-02 Thread Matt
Hi, I have a question about reformatting data. It looks like it should
be simple, but I've been working at it for awhile now and it's about
time I ask for help.

My data look like this:

ITEM VALUE STEP
item1 A  first
item2 C  first
item2 D  second
item1 A  second
item3 A  first
item3 B  second
item3 A  third

I just want to transform it so they look like this:

ITEM FIRST SECOND THIRD
item1 A ANA
item2 C DNA
item3 A BA

Basically taking the values of the STEP column and using those as
the column names and merging together the items.

I appreciate your help,
-Matt

__
R-help@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.


Re: [R] Transform values from one column into column names of new dataframe

2008-05-02 Thread hadley wickham
On Fri, May 2, 2008 at 11:05 AM, Matt [EMAIL PROTECTED] wrote:
 Hi, I have a question about reformatting data. It looks like it should
  be simple, but I've been working at it for awhile now and it's about
  time I ask for help.

  My data look like this:

  ITEM VALUE STEP
  item1 A  first
  item2 C  first
  item2 D  second
  item1 A  second
  item3 A  first
  item3 B  second
  item3 A  third

  I just want to transform it so they look like this:

  ITEM FIRST SECOND THIRD
  item1 A ANA
  item2 C DNA
  item3 A BA

  Basically taking the values of the STEP column and using those as
  the column names and merging together the items.

Have a look at the reshape package (http://had.co.nz/reshape):

install.packages(reshape)
library(reshape)

names(mydf) - tolower(names(mydf))
cast(mydf, item ~ step, length)
cast(mydf, item ~ step, function(x) x[1])

Hadley

-- 
http://had.co.nz/

__
R-help@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.


Re: [R] Transform values from one column into column names of new dataframe

2008-05-02 Thread Henrique Dallazuanna
Try this also:

noquote(with(x, tapply(VALUE, list(ITEM, STEP), paste)))

On Fri, May 2, 2008 at 1:05 PM, Matt [EMAIL PROTECTED] wrote:

 Hi, I have a question about reformatting data. It looks like it should
 be simple, but I've been working at it for awhile now and it's about
 time I ask for help.

 My data look like this:

 ITEM VALUE STEP
 item1 A  first
 item2 C  first
 item2 D  second
 item1 A  second
 item3 A  first
 item3 B  second
 item3 A  third

 I just want to transform it so they look like this:

 ITEM FIRST SECOND THIRD
 item1 A ANA
 item2 C DNA
 item3 A BA

 Basically taking the values of the STEP column and using those as
 the column names and merging together the items.

 I appreciate your help,
 -Matt

 __
 R-help@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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[alternative HTML version deleted]]

__
R-help@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.