I have data in this form
id year facname class_code line_no value
1 1 A County 1 county1
1 1 A County 2 county2
1 1 A source1 1 9
1 1 A source1 2 4
1 1 A source2 1 7
1 1 A source2 2 2
1 1 A source3 1 8...
2 1 B County 1 county1
2 1 B County 2 county1
2 1 B source1 1 21
2 1 B source1 2 9
2 1 B source2 1 4
2 1 B source2 2 7 ....
I am trying to convert this into something like this : (note the last 3 columns will have the values 'spread' accordingly)
id year facname line_no County source1 source2 source3
1 1 A 1 county1 9 7 8
1 2 A 2 county2 4 2 NA
1 3 A 3 county3
1 4 A 4 county4
2 1 B 1 county1
2 2 B 2 county2
2 3 B 3 county3
2 4 B 4 county4
This will show the different number of payers (source1,source2, source3) and the county names (county1, county2) that the counties belong to. I know its some combination of spread (and possibly gather) but I'm unable to put my head around it.
Any help is appreciated, thanks!
(PS: I understand this is probably a duplicate question but I'm really new to tidying data)
edit: The counties (county1,2..etc.) are actually numbers (in the original dataset) but are categorical in nature, so I'm calling them as county1, the other values (sources) are actually number of people in that county participating in events (source1, source2 etc.). There are a total of 40 line_no's for each facility.
county
? Its not very clear from data. – MKRcounty1
and for others you have mentioned anumber
. For consistency, can we not useconuty1
,county2
,county3
etc. Is that the way your data will be? – MKR