0

I would like to apply format Currency to row 3 and 4 of this sample data frame. Is it possible to do it by row? I know there are functions (such as DT::formatCurrency) that can do it by column.

Thanks in advance!

Dataset:

A <- c(100, 7, 10000, 2000)
B <- c(150, 8, 21000, 25000)
C <- c(200, 5, 15000, 20000)

df <- data.frame(A, B, C)

Desired output:

enter image description here

Ketty
  • 811
  • 10
  • 21
  • What is the logic? Why do you choose these two rows? – NelsonGon Jul 17 '19 at 17:35
  • 1
    You can do this, but it will convert all the columns to character `df[3:4,] <- lapply(df[3:4,], scales::dollar)`. – IceCreamToucan Jul 17 '19 at 17:56
  • NelsonGon, those two rows represent total sales from current year and previous year. – Ketty Jul 17 '19 at 18:29
  • @IceCreamToucan, that works. Thanks! Question: which part of your code converts all columns to character? – Ketty Jul 17 '19 at 18:33
  • 1
    The `scales::dollar` function converts its input to character, so by applying that to all columns you are converting them all to character (it isn't possible to convert only specific rows to character) – IceCreamToucan Jul 17 '19 at 18:35

0 Answers0