parsing data, reo-organizing using group_split

I have this dataframe, which I want to re-format to have one row for every county and column for every cluster (51 columns for each row). Right now it has a row for every possible county-cluster combination (so 51X as many rows as I want). I only need the value for "Rest.of.EA.LQ"

structure(list(county_fips_code = c(45001, 45001, 45001, 45001, 
45001, 45001, 45001, 45001, 45001, 45001, 45001, 45001, 45001, 
45001, 45001, 45001, 45001, 45001, 45001, 45001, 45001, 45001, 
45001, 45001, 45001, 45001, 45001, 45001, 45001, 45001, 45001, 
45001, 45001, 45001, 45001, 45001, 45001, 45001, 45001, 45001, 
45001, 45001, 45001, 45001, 45001, 45001, 45001, 45001, 45001, 
45001, 45001, 22001, 22001, 22001, 22001, 22001, 22001, 22001, 
22001, 22001), County = c("Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Abbeville County, SC", "Abbeville County, SC", 
"Abbeville County, SC", "Acadia Parish, LA", "Acadia Parish, LA", 
"Acadia Parish, LA", "Acadia Parish, LA", "Acadia Parish, LA", 
"Acadia Parish, LA", "Acadia Parish, LA", "Acadia Parish, LA", 
"Acadia Parish, LA"), Cluster = c("Aerospace Vehicles and Defense", 
"Agricultural Inputs and Services", "Apparel", "Automotive", 
"Biopharmaceuticals", "Business Services", "Coal Mining", "Communications Equipment and Services", 
"Construction Products and Services", "Distribution and Electronic Commerce", 
"Downstream Chemical Products", "Downstream Metal Products", 
"Education and Knowledge Creation", "Electric Power Generation and Transmission", 
"Environmental Services", "Financial Services", "Fishing and Fishing Products", 
"Food Processing and Manufacturing", "Footwear", "Forestry", 
"Furniture", "Hospitality and Tourism", "Information Technology and Analytical Instruments", 
"Insurance Services", "Jewelry and Precious Metals", "Leather and Related Products", 
"Lighting and Electrical Equipment", "Livestock Processing", 
"Marketing, Design, and Publishing", "Medical Devices", "Metal Mining", 
"Metalworking Technology", "Music and Sound Recording", "Nonmetal Mining", 
"Oil and Gas Production and Transportation", "Paper and Packaging", 
"Performing Arts", "Plastics", "Printing Services", "Production Technology and Heavy Machinery", 
"Recreational and Small Electric Goods", "Textile Manufacturing", 
"Tobacco", "Trailers, Motor Homes, and Appliances", "Transportation and Logistics", 
"Upstream Chemical Products", "Upstream Metal Manufacturing", 
"Video Production and Distribution", "Vulcanized and Fired Materials", 
"Water Transportation", "Wood Products", "Aerospace Vehicles and Defense", 
"Agricultural Inputs and Services", "Apparel", "Automotive", 
"Biopharmaceuticals", "Business Services", "Coal Mining", "Communications Equipment and Services", 
"Construction Products and Services"), County.LQ = c(0, 0, 0, 
3.1730614, 0, 0.054751392, 0, 0.40251535, 0.42340145, 0.30231148, 
0, 2.9028628, 2.1356323, 0, 0, 0.5180955, 0, 0, 0, 2.5984058, 
3.1713812, 0.21728677, 0, 0, 0, 5.61731, 22.721928, 0, 0, 0, 
0, 0.36617142, 0, 0, 0, 0, 0.47610378, 6.124802, 0, 1.4715167, 
0, 67.96229, 0, 7.512582, 0.20101942, 0, 0, 0, 0, 0, 3.820732, 
0, 5.532152, 0, 0.14022271, 12.87349, 0.27745262, 0, 0.31128657, 
3.6836877), Rest.of.EA.LQ = c(0.540255943770136, 0.606947758875614, 
1.52778486789079, 4.75108751816265, 1.70001525183178, 0.611264424726288, 
0, 0.977238344016417, 1.15316782500607, 0.966827161655383, 3.47902177768104, 
0.755482737281471, 0.869094462985398, 2.76578761561315, 1.14319807471808, 
0.464922926765636, 0.0589484139310556, 0.557050783687028, 0.284397471899125, 
1.33539565356669, 0.625583161092602, 0.42113259601999, 0.588464342790257, 
0.16092914002819, 0.0867355937299084, 1.73622371819498, 2.74309990350475, 
1.26850838166412, 0.497079819838406, 0.255985964758908, 0, 1.67414570183492, 
0.46273477064668, 0.969710088991223, 0.0691877832076574, 2.22377957378644, 
0.384914768909613, 3.64586781164697, 1.12479753603332, 2.96170079851518, 
1.01209340725309, 13.2973253531152, 0.160035212402153, 2.78779503512433, 
0.782619484252328, 1.01744472314417, 0.923182810952556, 0.351577895389053, 
5.05217379216473, 0.28780304487939, 1.16182597768683, 0.116455461368066, 
1.20325511560345, 0.198423503541645, 0.167211140241707, 0, 0.46255168887017, 
0.0788534167607113, 1.45359524685817, 4.16830758133393)), row.names = c(NA, 
60L), class = "data.frame")

I am trying to use group_by and group_split which works to separate into groups by Cluster, but not I'm not sure where to go next?

Any ideas?

Thanks!

I used tidyr::spread

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.