'Minimum between column value and global value in R
I would like to have the minimum value between a fixed value and a calculation from a column
For example i have the following data :
beta = data.frame(A = c(1,2,3,4,5,6,7,8,9))
And i would like to know the minimum between A/2 and the value 3
My problem is when i use the min function in R, he takes the minimum of all the column A instead of calculating line by line. So when i create beta$min = min(beta$A/2, 3)
, i get this:
> beta
A min
1 1 0.5
2 2 0.5
3 3 0.5
4 4 0.5
5 5 0.5
6 6 0.5
7 7 0.5
8 8 0.5
9 9 0.5
So he always take the minimum of the column A (1).. how could i do this line by line ?
Thanks for reading
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|