If I have a dataframe as follows, with a combination of text values and NA cells:
id | Col1 | Col2 | Col3 | Col4 | Col5 | Col... |
---|---|---|---|---|---|---|
id1 | NA | NA | sample | NA | weight | etc |
id2 | NA | size | NA | NA | NA | etc |
id3 | volume | size | sample | NA | NA | etc |
id4 | NA | NA | NA | qty | NA | etc |
id5 | NA | NA | sample | qty | weight | etc |
Is it possible to rename the header with the most frequently used value in that column, as follows?
id | volume | size | sample | qty | weight |
---|---|---|---|---|---|
id1 | NA | NA | sample | NA | weight |
id2 | NA | size | NA | NA | NA |
id3 | volume | size | sample | NA | NA |
id4 | NA | NA | NA | qty | NA |
id5 | NA | NA | sample | qty | weight |