Home How do we use global variable in r inside a quotation
Reply: 0

How do we use global variable in r inside a quotation

user2727
1#
user2727 Published in May 21, 2018, 3:00 am

I wrote all these myself (please look at the codes below ###) but I think there must be some way to do this inside a loop. How do I edit the code to write a loop something like:

i=10

for (i in 10 to 80){

    j=i+5

    age_only$agecat[age_only$CI_Age.at.Adverse.Event>=i &        
               age_only$CI_Age.at.Adverse.Event<j] <- "Between i and j-1"

    i=j
 }

I don't know how to use i/j inside a quotation mark.

#
age_only$agecat[age_only$CI_Age.at.Adverse.Event] <- "Above 85"    
age_only$agecat[age_only$CI_Age.at.Adverse.Event<5]<-"Below 5"     
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=5 & age_only$CI_Age.at.Adverse.Event<10]<-"Between 5 to 9"     
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=10 & age_only$CI_Age.at.Adverse.Event<15]<- "Between 10 to 14"    
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=15 & age_only$CI_Age.at.Adverse.Event<20]<- "Between 15 to 19"    
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=20 & age_only$CI_Age.at.Adverse.Event<25]<- "Between 20 to 24"    
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=25 & age_only$CI_Age.at.Adverse.Event<30]<- "Between 25 to 29"    
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=30 & age_only$CI_Age.at.Adverse.Event<35]<- "Between 30 to 34"    
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=35 & age_only$CI_Age.at.Adverse.Event<40]<- "Between 35 to 39"    
  age_only$agecat[age_only$CI_Age.at.Adverse.Event>=40 & age_only$CI_Age.at.Adverse.Event<45]<-"Between 40 to 44"      
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=45 & age_only$CI_Age.at.Adverse.Event<50]<- "Between 45 to 49"    
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=50 & age_only$CI_Age.at.Adverse.Event<55]<-"Between 50 to 54"
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=55 & age_only$CI_Age.at.Adverse.Event<60]<- "Between 55 to 59"
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=60 & age_only$CI_Age.at.Adverse.Event<65]<- "Between 60 to 64"
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=65 & age_only$CI_Age.at.Adverse.Event<70]<- "Between 65 to 69"
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=70 & age_only$CI_Age.at.Adverse.Event<75]<- "Between 70 to 74"
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=75 & age_only$CI_Age.at.Adverse.Event<80]<- "Between 75 to 79"
age_only$agecat[age_only$CI_Age.at.Adverse.Event>=80 & age_only$CI_Age.at.Adverse.Event<85]<- "Between 80 to 84"`
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312467 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO