I have a large dataset with ~1 mil rows and 8 cols (variables). One of those variables, ORDER, has categories from 1 to 90. I want to create a new data.frame with a reduced number of categories for the variable ORDER (4) 1, 2, 3+ and ALL, where ALL is the sum FREQUENCY for all categories (1-90) and 3+ is the sum of FREQUENCY for categories >=3 (so 3 to 90).
YEAR PROVINCE ZONA91OK AGE5 ORDER NATIONALITY_MOTHER NATIONALITY_FATHER FREQUENCY
1979 1 101 15 1 No computable No computable 10
1989 3 102 20 1 No computable No computable 50
I am very new in data management with R so any help on the issue is very much appreciated!
Here is a sample of the data.frame
mydata<-structure(list(YEAR = c(1981, 1981, 1981, 1981, 1981, 1981, 1981,
1981, 1981, 1981, 1981, 1981, 1981, 1981, 1981, 1981, 1981, 1981,
1981, 1981, 1981), PROVINCE = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ZONA91OK = c(101, 101, 101,
101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
101, 101, 101, 101, 101), AGE5 = c(15, 20, 20, 25, 25, 25, 25,
30, 30, 30, 30, 30, 35, 35, 35, 35, 35, 35, 40, 40, 40), ORDER = c(1,
1, 2, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 12, 1, 3, 5),
NATIONALITY_MOTHER = structure(c(9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L
), .Label = c("España", "UE-15 y PD", "Resto Europa", "Magreb",
"África Sub-sahariana", "Latinoamérica", "Asia", "Resto del Mundo",
"No computable"), class = "factor"), NATIONALITY_FATHER = structure(c(9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L), .Label = c("España", "UE-15 y PD", "Resto Europa",
"Magreb", "África Sub-sahariana", "Latinoamérica", "Asia",
"Resto del Mundo", "No computable"), class = "factor"), FREQUENCY = c(10,
40, 20, 50, 30, 10, 1, 10, 15, 10, 1, 1, 5, 5, 5, 1, 1, 1,
1, 1, 1)), .Names = c("YEAR", "PROVINCE", "ZONA91OK", "AGE5",
"ORDER", "NATIONALITY_MOTHER", "NATIONALITY_FATHER", "FREQUENCY"
), row.names = 60175:60195, class = "data.frame")