Good day everyone, been trying to find a way to add a column based on conditions inside the same dataframe , for example using mtcars how can I multiply by 2 all the rows that meet condition mpg*cyl=126 and add the result in another column at the end? those that meet the condition will add the result and those that not will put a 0 as a result:
How to multiply by 2 all the rows that meet condition mpg*cyl=126 and add the result in another column at the end? Those that meet the condition will add the result and those that not will put a 0 as a result.
Hi! It sounds like you're trying to multiply the subset filter(mtcars, mpg * cyl == 126) by 2, zero-fill the subset filter(mtcars, mpg * cyl != 126), and preserve the existing columns in mtcars.
If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: