I'd like to cut
my data based on a conditional statement in the break parameter, but it's throwing this error:
Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), nrow = nr, : length of 'dimnames' [2] not equal to array extent
Is it possible to use a conditional statement inside cut
in this way?
Sample Data
df <- structure(list(fyear = c(1970, 1970, 1970, 1970, 1970, 1970,
1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970,
1970, 1970, 1970), BEME = c(0.39713747645951, 0.548988782444936,
0.537154930871343, 1.89357008340059, 1.66945262543448, 0.969181836638018,
1.09989952916609, 0.858308443214104, 0.292175536881419, 0.684685677549708,
0.338422675433708, 3.02671555788371, 0.422643864469658, 0.805317430736738,
0.529954031556715, 0.617716486520065, 0.911576593365635, 0.4131850675139,
1.16211278792693, 2.13177678851802), exchg = c(11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 11L, 11L, 12L, 11L, 12L,
19L, 11L, 11L, 11L)), .Names = c("fyear", "BEME", "exchg"), class = c("tbl_df",
"data.frame"), row.names = c(NA, -20L))
Cut
function
cut(df$BEME, breaks = quantile(df[df$exchg == 11, 2], c(0,0.3,0.7,1)), labels = FALSE)