
Adding a column to a data.frame?
I have the data.frame below. I want to add a column that classifies my data according to column 1 (`h_no`) in that way that the first series of h_no 1,2,3,4 is class 1, the second series of `h_no` (1 to 7) is class 2 etc. such as indicated in the last column. h_no h_freq h_freqsq 1 0.09091 0.008264628 1 2 0.00000 0.000000000 1 3 0.04545 0.002065702 1 4 0.00000 0.000000000 1 1 0.13636 0.018594050 2 2 0.00000 0.000000000 2 3 0.00000 0.000000000 2 4 0.04545 0.002065702 2 5 0.31818 0.101238512 2 6 0.00000 0.000000000 2 7 0.50000 0.250000000 2 1 0.13636 0.018594050 3 2 0.09091 0.008264628 3 3 0.40909 0.167354628 3 4 0.04545 0.002065702 3
More
1 Expert Answer
library(dplyr)
res <- df %>% mutate(NEW_h_no=cut(h_no, breaks=c(1, 4, 7, 10), labels=c("Class1","Class2","Class3")))
Bons estudos!
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Jacob W.
If you could create a reproducible example of your data.frame that one of us could enter into R, that will make helping you much easier. As is, it is not clear how the series of numbers you posted is organized in the data frame.01/14/20