1

I have one dataset

sn   Name   Feature  score
1    pen-1     cost      2
2    pen-1     color     3
3    pen-1     look      1
4    pen-2     cost      1
5    pen-2     color     2
6    pen-2     look      4

I want to change it to the below format

sn  Name    Cost Look color
 1  Pen-1    2    1    3 
 2  pen-2    1    4    2

Please Solve My problem using R Programming. Thanks

Agaz Wani
  • 5,514
  • 8
  • 42
  • 62
Rajesh
  • 77
  • 1
  • 1
  • 7
  • Your `sn` column in the result doesn't make sense. Why should it be `1, 2`? Why not `1,4`? Both `sn:1` and `sn:2` are associated with `pen-1` – thelatemail May 05 '16 at 05:59

1 Answers1

1

We can use dcast

library(reshape2)
dcast(df1, Name~Feature, value.var="score")

Or spread from tidyr

library(tidyr)
spread(df1[-1], Feature, score)
#   Name color cost look
#1 pen-1     3    2    1
#2 pen-2     2    1    4
akrun
  • 874,273
  • 37
  • 540
  • 662