1

i created a dataframe and added a row

like this

  name     A2016     A2017     E2018      E2019      E2020
1 sale 6769.0000 9581.0000 11304.000 13170.0000 15303.0000
2   op  926.0000 1472.0000  1829.000  2169.0000  2550.0000
3   ni  857.0000 1236.0000  1584.000  1876.0000  2194.0000
4  eps    0.4800    0.5800     0.750     0.8800     1.0300
5  eps    7.9776    9.6396    12.465    14.6256    17.1186

and i tried to change the value at [5,'name']

table[5,'name'] <- 'pe' 

but it didn't work, value was changed to #NA then i tried

table[5,'name'] <- 'eps' 

value changed back to 'eps'

why? do you know why i can't change to 'pe'?

  • 2
    Is name a `factor` or a character? – MHammer Jul 05 '18 at 04:22
  • 1
    R uses Error and Warning messages to help you identify problems. When you tried to change the value, did you get this message? "*Warning message: In `[<-.factor(`*tmp*`, 1, value = "a")` : invalid factor level, NA generated*" – Gregor Thomas Jul 05 '18 at 04:24
  • `class(table$name)` must be a `factor`, you need to convert it into character before inserting a new value or add new factor level. Also, `table` is not a good name for the dataframe as it is an internal function. – Ronak Shah Jul 05 '18 at 04:25
  • 1
    Suggested dupe: [Warning message: In … : invalid factor level, NA generated](https://stackoverflow.com/q/16819956/903061) – Gregor Thomas Jul 05 '18 at 04:26
  • 1
    right! i never think about the factor! thank you so much!!!! – JUNSEONG LEE Jul 05 '18 at 05:15

0 Answers0