Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 204922

How to string replace rows in a data table

$
0
0

I'm working with GSS data, and one of their variables is Total family income. I think that they unnecessarily split up income below 10,000 into 8 groups, so I want to join them all together. I went about doing this with string_replace, but it doesn't seem to recognize the commands.

I run:

GSS2018$`Total family income` <- str_replace(GSS2018$`Total family income`,
                                                 "Under $1 000",
                                                  "Under $10000")
GSS2018$`Total family income` <- str_replace_all(GSS2018$`Total family income`,
                                                 "$1 000 to 2 999",
                                                 "Under $10000")
GSS2018$`Total family income` <- str_replace_all(GSS2018$`Total family income`,
                                                 "$3 000 to 3 999",
                                                 "Under $10000")
GSS2018$`Total family income` <- str_replace_all(GSS2018$`Total family income`,
                                                 "$4 000 to 4 999",
                                                 "Under $10000")
GSS2018$`Total family income` <- str_replace_all(GSS2018$`Total family income`,
                                                 "$5 000 to 5 999",
                                                 "Under $10000")
GSS2018$`Total family income` <- str_replace_all(GSS2018$`Total family income`,
                                                 "$6 000 to 6 999",
                                                 "Under $10000")
GSS2018$`Total family income` <- str_replace_all(GSS2018$`Total family income`,
                                                 "$7 000 to 7 999",
                                                 "Under $10000")
GSS2018$`Total family income` <- str_replace(GSS2018$`Total family income`,
                                                 "$8 000 to 9 999",
                                                 "Under $10000")

However, nothing seems to change after I run these. The strings just remain the same. What am I doing wrong here?


Viewing all articles
Browse latest Browse all 204922

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>