简体   繁体   中英

perform rank on multiple columns in a data frame in one line of code

I have a "source" data frame that with data in 3 columns. I would like to rank the variables in each column and output into a new data frame.

This code works for one column. Can I write this formula to include other columns?

SortedFundamentals1 <- as.data.frame(rank(EquityFundamentals$Forward.PE))

This works on one column, but can I put in the other columns and do them all at once? The ranking is independent for each column.

The other columns are: FCF.Yield and Operating.Margin

This shroud work


SortedFundamentals1 = 
        as.data.frame( do.call(cbind, 
                               list(rank(EquityFundamentals$Forward.P.E),
                                    rank(EquityFundamentals$FCF.Yield),
                                    rank(EquityFundamentals$Operating.Margin))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM