I need to create a pivot table in R that will have text values instead of aggregated SUM or AVERAGE functions. Something like in the example below:
Original table (in a dataframe with fields User, Field, Text):
User | Field | Text
Group1 | Field 1 | Text content A
Group1 | Field 2 | Text content B
Group2 | Field 1 | Text content C
Group2 | Field 2 | Text content D
Group3 | Field 1 | Text content E
The result that I need in R using cross tabulation:
User | Field 1 | Field 2
Group1 | Text content A | Text content B
Group2 | Text content C |Text content D
Group3 | Text content E |NA
I would then need to save the result as CSV… but that’s the easy part:)
Is there any way of achieving this?
Many thanks,
MA
This is what
reshape(going from ‘long’ format to ‘wide’ format). Other people prefer thereshapepackage, but both will do for this simple case.Here’s a solution with the base function: