You could just use the table
command:
table(data$id,data$week)
1 2 3
1 2 1 1
2 0 0 1
If “id” and “week” are the only columns in your data frame, you can simply use:
table(data)
# week
# id 1 2 3
# 1 2 1 1
# 2 0 0 1
More Related Contents:
- Group by multiple columns and sum other multiple columns
- Aggregate a dataframe on a given column and display another column
- Aggregate a data frame based on unordered pairs of columns
- Compute mean and standard deviation by group for multiple variables in a data.frame
- Returning first row of group
- Get the means of sub groups of means in R
- R use ddply or aggregate
- Convert an upper to lower triangle matrix in r [duplicate]
- summarizing multiple variables in group by
- Reshaping multiple sets of measurement columns (wide format) into single columns (long format)
- Aggregating by unique identifier and concatenating related values into a string [duplicate]
- Convert data from long format to wide format with multiple measure columns
- Add count of unique / distinct values by group to the original data
- dcast warning: ‘Aggregation function missing: defaulting to length’
- Select the top N values by group
- Fastest way to add rows for missing time steps?
- Applying a function to every row of a table using dplyr?
- Aggregate multiple columns at once [duplicate]
- aggregate methods treat missing values (NA) differently
- Is there a R function that applies a function to each pair of columns?
- Group integer vector into consecutive runs
- Create columns from factors and count [duplicate]
- Joining aggregated values back to the original data frame [duplicate]
- Object not found error with ddply inside a function
- R: Split unbalanced list in data.frame column
- R: Reshaping Multiple Columns from Long to Wide
- Can dcast be used without an aggregate function? [duplicate]
- Replace missing values (NA) in one data set with values from another where columns match
- Can `ddply` (or similar) do a sliding window?
- How can I count the number of NAs per group?