For loop in R through data.frame -


i have following data.frame

name<-c("jack","jerry","emma","andy","jayde","lynn","liam") education<-c("master","master","master","bach","bach","phd","phd") salary<-c(20000,20000,20000,30000,10000,70000,70000) people<-data.frame(name,education,salary) 

i have use loop (silly, know) loop through frame, find "education" level, , add salary increase.

how can done?

even though better mentioned in comments, can ugly way:

for (i in 1:nrow(people)) {   if (people$education[i] == "bach") {     people$salary[i] <- people$salary[i]+1000   } else if (people$education[i] == "master") {     people$salary[i] <- people$salary[i]+2000   } else {     people$salary[i] <- people$salary[i]+3000   } } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -