[R] Multiple if function
Bert Gunter
bgunter.4567 at gmail.com
Tue Sep 15 21:16:26 CEST 2015
Maria:
Have you read An Intro to R or other R tutorial? There are many on the
web and this is a basic idea that they would explain (with examples).
?ifelse ##a vectorized kind of if conditional
is one way to do this (though it can get a little convoluted). There
are others (e.g. splitting and recombining -- see the plyr package),
which others may suggest. Nevertheless, time spent with a tutorial
would be useful.
Cheers,
Bert
Bert Gunter
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
-- Clifford Stoll
On Tue, Sep 15, 2015 at 3:56 AM, Maria Lathouri <mlathouri at yahoo.gr> wrote:
> Dear all,
>
> I am writing as I would like your help. I have a dataframe with two columns, ASB and Flow, where the the first one has values 1, 2 or 3 and the second flow data. Something like that:
> ASBclass Flow1 11.51 9.2
> 2 10.5
> 3 6.7 ... ...
> I would like to produce a third column named eg. deviation where it would get me values based on if ASBclass is 1, multiply Flow by 0.1; if ASBclass is 2 then multiply Flow by 0.15 and if ASBclass is 3 then multiply by 0.2.
>
> If (ASBclass=1) { deviation<-Flow*0.1}
> If (ASBclass=2) { deviation<-Flow*0.15}If (ASBclass=1) { deviation<-Flow*0.2}
> I am not sure whether I should add the else function and how can I combine these separate functions.
>
> Can anyone help me on that?
> Thank you very much.
>
> Kind regardsMaria
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list