I have a data frame which I would like to sort by Column A largest to smallest, then cut and paste all rows that are negative to identical columns side beside the original, leaving 1 column gap in between, and then sorting the negative values smallest to largest.
Basically I would like to display the positive and negative values side by side for ease of reading so the user doesn't have to manually sort or scroll:
df <- data.frame(
A = c("2","-4","5","-9", NULL ),
B = c(1,3,2,3))
df
A B
1 2 1
2 -4 3
3 5 2
4 -9 3
The new data frame would look like this, with a blank space in between, and columns A and B would have the exact same names:
I think that your example was potentially an 'easy case' because there were as many negatives as positives, so the equal length would mean you could trivially cbind the two parts together.
However, with unequal parts as in my example, you would need a cbind that pads, I modified such a function to operate by converting to character and padding with blank string.