Sorting data in a table

Asked by At

I want to create a new excel output that I will use as an appendix for my paper and I want to create three columns and sort the table alphabetically by a column "namn". I have been applying a following code:

tabell<-count(data, "namn")
print(tabell)
print(tabell$namn)
tabell$proportion<-tabell$freq/sum(tabell$freq)
print(tabell$czestosc)
tabell2=data.frame(tabell$namn, tabell$freq, tabell$proportion)
# I have been attempting with ”=” as well as with ”<- ”

tabell2[order(tabell2$namn)]
tabell2[order(tabell2$namn, )]
tabell2[order(tabell2$namn, ), ]
tabell2[order(namn ) ]
tabell2[order(namn , )]
tabell2[order(namn, ), ]
#and all combinations of the last 6 commands with assignment to a    variable.

Nevertheless, it does not work.

Thank you in advance for your advice.

1 Answers

0
Nick On

Try:

newdf <- order(tabell2$ctr)

You don't need to index the data as per your examples, instead you can just create a new data frame based on the newly sorted values.