Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select a category in dataframe for operation in r?

Having this dataframe:

dat=data.frame(a=c("ll","pp","ml","ml","v"),value=c(1,2,12,1,2))

I want to multiply by 10 only values correspond to a=ml

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Another solution is to use a ifelse statement

dat %>% 
  mutate(value = ifelse(a == "ml", value*10, value))

   a value
1 ll     1
2 pp     2
3 ml   120
4 ml    10
5  v     2
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading