Replacement values of a column in a data frame in R -
I have data.fr Use mat . I would like to create the data frame
res , that means if the second column is 1, replace the first column value instead, and if it is 0, replace it with inf. How can I do this in R?
c1 = c (10, 1, 3, 4, 6, 8) c2 = c (1, 1, 0, 1, 0, 1) mat = data. Frames (c1 = C1, C2 = C2)> Mat C1 C2 1 10 1 2 1 1 3 3 4 4 1 5 6 0 6 8 1> C2 = C (10, 1, 4, inf, 8) & gt; Res = data.frame (C1 = C1, C2 = C2)> Res c1 c2 1 10 10 2 1 1 3 3 INF 4 4 5 6 INF 6 8 8
ifelse and try it:
& gt; (Res & lt; - Conv. (Mat, C2 = Eiffel (C2 == 1, C1, IP))) C 1 C 2 1 10 10 2 1 1 3 3 ING 4 4 4 5 6 INFO 6 8 8
Comments
Post a Comment