Relatively new to R but I have a list of names (each in a seperate column) that I want to combine into one list in alphabetical order
X <- c("ringo","paul","john","george")
Intended result: ("george", "john","paul","ringo")
I've tried a couple of different approaches including:
Arrange(x)
Sort(unlist(x))
And manually marking the order and then trying to index the element with an offset
x <- c("ringo","4","paul","3","john","2","george","1")
Which(x == 1)
But no luck so far. Apologies for the crappy explanation
Follow-up:
The data actually is set up like this in the dataframe pbptop:
a1.num a2.num
paul john
ringo george
using paste, list_concat or cbind basically gives me the following:
x <- paste0(pbptop$a1.num,pbptop$a2.num)
[1] pauljohn
[2] ringogeorge
What I want is to alphabetize within each list or string
[1]johnpaul
[2]georgeringo
> require(gtools)
> x <- paste0(pbptop$a1.num,pbptop$a2.num)
> mixedsort(x)
Unfortunately, mixedsort just alphabetized the set of list instead of each list individually and I couldn't get the other solutions to work.
paste(sort(pbptop$a1.num,pbptop$a2.num), collapse = ", ")
Error in sort(pbptop$a1.num, pbptop$a2.num) :
'decreasing' must be a length-1 logical vector.
Did you intend to set 'partial'?