dataframe - R padding time series with grouping -
i have data frame columns action, type, project_id, week, events_in_time
i want run analysis on each subgroup defined action, type. have problem padding time series (column week). projects don't have entry given week.
how can add 0 values in events_in_time missing weeks in projects?
i tried merging described here: https://bocoup.com/weblog/padding-time-series-with-r generating weeks , merging nothing happens. understand need generate projects can't find how it. did:
all.week.frame=data.frame(week=seq(0,12)) # fills first 12 weeks merged=merge(data, all.week.frame, all=t)
example data: http://pastebin.com/au3efbga
save file , load with
data= read.table("merged.csv", header = true, sep = ",")
update: found using
complete(data_filtered, nesting(type,action, project_id), week, fill = list(events_in_time = 0))
solves it
i think complete
tidyr
looking for. takes data.frame, followed columns complete (things make sure match up), list of values insert if combination missing. here, takes df
, makes combinations of week
, project_id
, fills other column (events_in_time
) 0
whenever there no entry.
complete(df, week, project_id, fill = list(events_in_time = 0))
Comments
Post a Comment