I have a dataset below I need to remove all whitespace between the three text columns and replace with a single comma. I tried a few options with gsub but nothing worked. I'd like to do this in R
gsub("^ *|(?<= ) | *$", ",", all_data, perl=T)
Sample below all spacing is different sizes in the file (the number is just a row number)
> [1] Pig Piggy 2
> [2] Chicken Chick 7
> [3] Cow Calf 3
Desired output:
Pig,Piggy,2
Chicken,Chick,7
Cow,Calf,3
Thanks in advance.