vendredi 12 novembre 2021

Urgent: classifying age groups of an age variable, comparing two of its corresponding other variables, if true then it should return those values in R

this is the code i am using to classify age groups and check if the store purchase variable is greater then return the cell store value. But, i am not receiving the answer as a vector instead, i am getting answer 4. So not sure whats wrong, i appreciate . mydata is the dataframe.

for(i in 1:nrow(mydata)){#opening the for loop

if(mydata$Age[i] > 25 & mydata$Age[i] < 30){#opening the if statement

vector_more_nstorepur2<-mydata$NumStorePurchases[which(my_clean_campaign$NumStorePurchases[i] > mydata$NumWebPurchases[i])] #opening for the second if statement }

else if(mydata$Age[i] >30 & mydata$Age[i] < 50){#opening the if statement

vector_more_nstorepur3<-mydata$NumStorePurchases[which(my_clean_campaign$NumStorePurchases[i] > mydata$NumWebPurchases[i])]#opening for the second if statement }#end of the if

else if(mydata$Age[i] >50 & mydata[i] < 60){#opening the if statement vector_more_nstorepur4<-mydata$NumStorePurchases[which(my_clean_campaign$NumStorePurchases[i] > mydata$NumWebPurchases[i])]#opening for the second if statement }

else if(mydata$Age[i] >60 & mydata$Age[i] <=80){#opening the if statement vector_more_nstorepur5<-mydata$NumStorePurchases[which(mydata$NumStorePurchases[i] > mydata$NumWebPurchases[i])]#opening for the second if statement }

}# end of the for loop

can anyone help what am i doing wrong? its for an assignment and need an urgent response please, asap (within an hour) would be great

Aucun commentaire:

Enregistrer un commentaire