dataframe - R: Transform 2 columns into a data frame based on counting column values -
i trying reshape 2 columns of data frame new data frame. both columns have text values. need count each combination of values , put them in data frame.
below example of 2 columns need use:
2 columns data frame:
col1 col2 z b z b z c x c z d x
desired output show count of each combination:
z x 1 0 b 2 0 c 1 1 d 0 1
thank you
you can use table
on dataset
table(df1) # col2 #col1 x z # 0 1 # b 0 2 # c 1 1 # d 1 0
if need output 'data.frame'
as.data.frame.matrix(table(df1))
Comments
Post a Comment