-1

I have a data frame:

mydata:

         Date  error  variable  value
1  2016-06-16     NA C13uptake     NA
2  2016-06-17 0.0004 C13uptake 0.0065
3  2016-06-18     NA C13uptake     NA
4  2016-06-19 0.0085 C13uptake 0.0625
5  2016-06-20 0.0106 C13uptake 0.0890
6  2016-06-21 0.0179 C13uptake 0.1825
7  2016-06-22     NA C13uptake     NA
8  2016-06-23 0.0065 C13uptake 0.1299
9  2016-06-16     NA     cal5C     NA
10 2016-06-17 0.0006     cal5C 0.0046
11 2016-06-18     NA     cal5C     NA
12 2016-06-19 0.0070     cal5C 0.0820
13 2016-06-20     NA     cal5C     NA
14 2016-06-21 0.0129     cal5C 0.1600
15 2016-06-22     NA     cal5C     NA
16 2016-06-23     NA     cal5C     NA
17 2016-06-24 0.0170     cal5C 0.1500

I would like to turn all error of the variable that are cal5C into NA's

i.e. if the factor (variable) is cal5C then its error is NA.

This i am pretty sure is a simple ifelse function - but it is not a function i have used much.

I thought it might be something like the following - but that is not working.

mydata$error <- ifelse(is.na(mydata$error) | mydata$variable %in% "cal5C")

Any help appreciated.

Lmm
  • 403
  • 1
  • 6
  • 24

1 Answers1

0

So the question is not unanswered...

You do not need an ifelse, just index in to the array elements that you want to set.

mydata$error[mydata$variable == "cla5C"] = NA
G5W
  • 36,531
  • 10
  • 47
  • 80