I 다음 dataframe 있습니다데이터 프레임의 비율에 새 열을 작성
dput(df1)
structure(list(month = c(1, 1, 2, 2, 3, 4), transaction_type = c("AAA",
"BBB", "BBB", "CCC",
"DDD", "AAA"), max_wt_per_month = c(54.9,
51.6833333333333, 52.3333333333333, 49.4666666666667, 49.85,
48.5833333333333), min_wt_per_month = c(0, 0, 0, 0, 0, 0), avg_wt_per_month = c(8.41701333107861,
7.65211141060198, 6.44184012508551, 7.74798927613941, 7.4360566888844,
7.50611319574734), prop = c(Inf, Inf, Inf, Inf, Inf, Inf)), .Names = c("month",
"transaction_type", "max_wt_per_month", "min_wt_per_month", "avg_wt_per_month",
"prop"), row.names = c(NA, -6L), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"), vars = list(month), drop = TRUE, indices = list(
0:5), group_sizes = 6L, biggest_group_size = 6L, labels = structure(list(
month = 1), row.names = c(NA, -1L), class = "data.frame", vars = list(
month), drop = TRUE, .Names = "month"))
내가 매달에 대한 최대 대기 시간의 비율을 포함 할 열 prop
을 만들려합니다. 나는이 코드를 실행하면, 나는 ... (특히 그것이 실제 데이터 세트에서 분명하다) 행 대부분의 Inf
값을 얻을 :
my_fun=function(vec){
100*as.numeric(vec[3])/
sum(with(data_merged_transactions, ifelse(month == vec[1], max_wt_per_month, 0))) }
data_merged_transactions$prop=apply(data_merged_transactions , 1 , my_fun)
난 다음 마지막으로 채워진 영역 차트를 생성해야하는 각 있도록 합이 0이 아닌 경우
ggplot(data_merged_transactions, aes(x=month, y=prop, fill=transaction_type)) +
geom_area(alpha=0.6 , size=1, colour="black")
가 왜 Inf
받을 수 있나요 : 지역은 100 % 중 비율 것입니까? 또한, 숫자가 아닌 월 (1 월, 2 월 등) 인 채워진 영역 차트를 만들 수 있습니까? 달 이름으로 월 ID를 대체하려고했지만 그 다음에 채워진 영역 대신 매우가는 막대가 나타납니다.
원본 데이터 프레임의 출력을 제공 할 수 있습니까? 내가 게시 한 것을 가져 오기 위해 고심하고 있습니까? 또한 '각 달에 대한 최대 대기 시간 비율'이 데이터 집합의 다른 변수의 함수로 무엇인지 자세히 설명 할 수 있습니까? – biomiha
@biomiha : 실제 데이터 세트가 큽니다. 방금 dput (head (df))을 게시했습니다. 최대 대기 시간의 %는 MAX_WT [AAA, january]/SUM (MAX_WT [1 월)]을 의미합니다. 여기서 max_wt는 세 번째 열이고 AAA는 특정 행의 transaction_type입니다. – FiofanS