Search code examples
rstatisticssubsetbioinformaticsdata-analysis

How do I change the value of a single variable in R to a range, where that range is dependent on the value of the original variable?


So I have data on CpG sites, and a column which defines their chromosomal position (e.g. 10000).

How would I change these values such that I can attain values in a range dependent on that original value. For example 10000 would be +/- 500 (9500 - 10500).

I'm going to be using the same parameters for each variable regardless of it's value.

I have tried

df$upstream <- df$value - 500
df$downstream <- df$value + 500

Which returns the upper and lower values I need, but how do I get this 'range' into a single column (e.g. such that I can search for it in genomebrowser)?


Solution

  • I worked with such dataset during and on my side, to perform this, I use to create new columns on my dataset using (as mentioned in the comment):

    df$upstream = df$position - 500
    df$downstream = df$position + 500
    

    Hope it helped