mardi 16 juillet 2019

In R applying if function to identify value of variable conditioning on the value of another variable

I am trying to identify the value of variable in an R data frame conditioning on the value of another variable, but unable to do it. for example

library(dplyr)
Dose=c(1,0.25,0.0625);Dose #Dose or Dilution
Protec1=c(5,4,3);Protec1
Protec2=c(5,5,5);Protec2
Protec3=c(5,4,5);Protec3
Protec4=c(3,4,5);Protec4
Total=c(rep(5,3));Total
df=as.data.frame(cbind(Dose,Protec1,Protec2,Protec3,Protec4,Total));df
df=df %>% mutate(Prop1=Protec1/Total);df
df=df %>% mutate(Prop2=Protec2/Total);df
df=df %>% mutate(Prop3=Protec3/Total);df
df=df %>% mutate(Prop4=Protec4/Total);df

I want to find out, what is the minimum value of Dose for which Prop1==1. For example the minimum value of Dose for which Prop1==1 is 1.0 (decreasing trend). However, in case of trend is like Prop2, Prop3, Prop4 (same value, no trend, increasing trend), also I want to have the result as Dose==1.0. can someone explain how to do it in R?. thanking you in advance

Aucun commentaire:

Enregistrer un commentaire