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

Seek and replace certain values in R

$
0
0

I know that this has been asked thousand times already but the answers don't work for me.

I have a big dataset and need R to automatically seek and replace certain values in certain columns for me.

I tried this: df$column <- replace (df$column, df$column, old number==new number)

for me it would look like this: df$qual_a_a_s1m1a <- replace(df$qual_a_a_s1m1a, df$qual_a_a_s1m1a, 2==3)

If I get this to work, I could then build this for all columns and all values.

Can you explain why it doesn't work? Thanks and have a nice sunday :)

EDIT: This is one of the results I get: replace(df$qual_a_a_s1m1a, df$qual_a_a_s1m1a, 6==1)

[1] 0 0 NA 6 NA 0 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 2 NA [32] NA NA NA NA 1 NA NA NA NA NA NA NA NA 6 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [63] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [94] NA NA NA NA NA NA NA NA 6 NA NA NA NA NA NA

Instead of replacing the sixes with ones it put two zeroes in there at the first two positions.


Viewing all articles
Browse latest Browse all 206019

Trending Articles



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