To sort a dataframe according to a specific pattern in a variable, you can use the arrange()
function from the dplyr
package in combination with a regular expression. Here's an example of how to sort a dataframe by the numbers in a variable called "numbers":
main.r270 chars11 lines
In this example, we are using the gsub()
function to remove all non-numeric characters from the "numbers" variable using the regular expression "[^0-9.]"
. We then convert the resulting character vector to numeric using the as.numeric()
function and sort the dataframe using arrange()
.
gistlibby LogSnag