I have a file with 3 columns. the 1st column is ID
, 2nd and 3rd are values for 2 conditions. in condition columns I have both -
and +
values. I would like to make 2 separate files. the 1st one would be for the negative values and the 2nd one would be for the positive values. do you know how to that in R?
Asked
Active
Viewed 69 times
-2

ARM
- 99
- 1
- 10
-
1Add [reproducible example](http://stackoverflow.com/questions/5963269) and expected output. 2 columns with 2 different values, would give you 4 outputs: `"--", "-+", "+-", "++"` ? – zx8754 Jul 18 '17 at 10:18
1 Answers
1
Something like this ?
set.seed(1)
df1 <- data.frame(id=1:5,cond1 = sample(-100:100,5), cond2 = sample(-100:100,5))
df_neg <- df_pos <- df1
df_pos[,2:3][df1[,2:3]<0] <- NA # or 0, or NULL
df_neg[,2:3][df1[,2:3]>0] <- NA # or 0, or NULL
# > df1
# id cond1 cond2
# 1 1 -47 80
# 2 2 -26 88
# 3 3 13 31
# 4 4 79 24
# 5 5 -61 -88
# > df_pos
# id cond1 cond2
# 1 1 NA 80
# 2 2 NA 88
# 3 3 13 31
# 4 4 79 24
# 5 5 NA NA
# > df_neg
# id cond1 cond2
# 1 1 -47 NA
# 2 2 -26 NA
# 3 3 NA NA
# 4 4 NA NA
# 5 5 -61 -88

moodymudskipper
- 46,417
- 11
- 121
- 167