adding a column in R to a dataframe [duplicate]
问题 This question already has an answer here : How to add a factor column to dataframe based on a conditional statement from another column? (1 answer) Closed 6 years ago . How do I add a column to a dataframe in R based on values in another column of a dataframe ? For eg if I have one column as x$n = [1,2,3,4,5,6] (values in other colums dont exactly matter. And I want another column as a 'category' column that assigns value 0 if x$n < 2, 1 if x$n is between 3 and 4 and 3 if x$n > 4. So that my