replacement has 45781858 rows, data has 1752611

I think this was asked already before, but I cannot find a solution for my issue. I have the following data frame

 (obj_1 <- data.frame (
      yr = c(1990, 1990, 1990, 1992, 1992, 1992),
      EARNWEEK= c(223, 200, 234, 500, 700, 800),
      AHRSWORKT= c(50, 40, 35, 35, 35, 40),
      WAGE = c(10, 8, 8, 9, 10, 9)
   ))

I would like created a column named REALWAGE, where I insert in each row the value of the variable WAGE multiplied by a value, which differs across the years. As I try to run the following code ...

obj_1[obj_1$yr %in% 1992,"REALWAGE"] <- obj_1$WAGE*1.223

and so on for the next year

obj_1[obj_1$yr %in% 1993,"REALWAGE"] <- obj_1$WAGE*1.153

... the error replacement has 45781858 rows, data has 1752611 is getting displayed. How is it possible to fix that?

Many thanks in advance!!

There are 1752611 rows that meet your condition of 1992.
You are trying to assign 45781858, I.e a value from every row of your table in their place. It doesn't fit. The answer is to also filter the rows on the right that you assign from

1 Like

You'd probably be better recoding the year into some sort of scaling factor, and then multiplying the wage by that rescaled value.

obj_1$scale <- recode(obj_1$WAGE,
  `1992` = 1.223,
  `1993` = 1.153,
  ...
  )
obj_1$REALWAGE <- obj_1$scale*obj_1*WAGE
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.