mercredi 17 février 2021

Using if within for loop, to make fold change obvious in R

In R I am trying to convert my fold change data. My fold change data was downloaded the wrong way around - so a ratio of 1/2 = 0.5, should read a 2 fold increase. Likewise a 2 fold increase, I'd like to change to a 2-fold decrease. Make sense? Here's a little example of my code

```head(data)
```FC_2wk  FC_4wk FC_3day FC_5day
```1 0.18585 0.13578 6.73210 0.17627
```2 0.20199 0.15551 5.27970 0.22444
```3 2.10320      NA 0.16343 6.19910
```4 5.96010      NA      NA 8.00570
```5 0.46983 0.43171      NA      NA
```6      NA 0.48625      NA      NA

I've writtent the following code - it almost works, but not quiet - what am I doing wrong?

```for(i in 2:ncol(data)){
```  if(data[,i] < 1){
```    data[,i] <- 1/data[,i]
```  }
```else {
```  data[,i] <- data[,i]*-1
```}
```}

Many many thanks in advance,
EC

Aucun commentaire:

Enregistrer un commentaire