0

I'm stuck again at an error I don't understand. I have a big data.frame with multiple stock parameters, such as price earnings ratio etc. Now I want to calculate between columns, i.e.:

MyDataFrame$NewColumn = MyDataFrame$Column1/MyDataFrame$Column2

This worked. However this doesn't work an generates an error:

Index$ValuationScore = 0.3*Index$PE1_Score + 0.2*Index$PE2_Score + 0.1*Index$PE3_Score

The scores are values between 1-6. The first 60 rows of my table don't contain any data only NAs since I need to calculate an average earlier on looking back 60 periods. The error message I get is:

Warning messages:
1: In Ops.factor(0.3, Index$PE1_Score) : * not meaningful for factors
2: In Ops.factor(0.2, Index$PE2_Score) : * not meaningful for factors
3: In Ops.factor(0.1, Index$PE3_Score) : * not meaningful for factors
10
  • 1
    Might be helpful when posting here in the future to use Sys.setenv(LANGUAGE="en") before your code so that errors/warnings come out in English. I've edited your question accordingly.
    – Thomas
    Oct 7, 2013 at 12:03
  • 3
    You need to convert your variables to something other than factor, perhaps numeric.
    – Thomas
    Oct 7, 2013 at 12:04
  • Thx alot for both, learned something again :-) This works. However what's the difference between factor and numeric? In the first case the division worked..this is strange since MyDataFrame$NewColumn in my example is actually how I've calculated these PE_Scores. So they must be already numeric actually aren't they?
    – MichiZH
    Oct 7, 2013 at 12:08
  • 1
    Hard to say without seeing str(Index).
    – Thomas
    Oct 7, 2013 at 12:11
  • Looked at it and the division is done with to num columns, whereas the multiplication was tried on a factor column. So the factor column is a result of the division of two num columns. Does this makes sense?
    – MichiZH
    Oct 7, 2013 at 12:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.