如何通过删除重复项并添加出现频率(而不是在R中)来扩大此数据帧?

如何通过删除重复项并添加出现频率(而不是在R中)来扩大此数据帧?,r,bigdata,data-manipulation,R,Bigdata,Data Manipulation,我试过下面的代码,但频率列只给出0和1。我要实际的数目 data2 <- as.data.frame(table(unique.data.frame(data)))) 我想要这个: ID Rating Freq 12 Good 2 16 Good 1 16 Bad 1 16 Very Bad 1 34 Very Good 1 您可以在dplyr library(dplyr) df %>% group_by

我试过下面的代码,但频率列只给出0和1。我要实际的数目

data2 <- as.data.frame(table(unique.data.frame(data))))
我想要这个:

ID    Rating    Freq
12    Good      2
16    Good      1
16    Bad       1
16    Very Bad  1
34    Very Good 1

您可以在
dplyr

library(dplyr)
df %>% group_by(ID, Rating) %>% tally()
并自动排序:

df %>% group_by(ID, Rating) %>% tally(sort = TRUE)

您可以在
dplyr

library(dplyr)
df %>% group_by(ID, Rating) %>% tally()
并自动排序:

df %>% group_by(ID, Rating) %>% tally(sort = TRUE)

您可以在
dplyr

library(dplyr)
df %>% group_by(ID, Rating) %>% tally()
并自动排序:

df %>% group_by(ID, Rating) %>% tally(sort = TRUE)

您可以在
dplyr

library(dplyr)
df %>% group_by(ID, Rating) %>% tally()
并自动排序:

df %>% group_by(ID, Rating) %>% tally(sort = TRUE)

您可以使用
count()
函数,并结合
ID
评级进行计数:

> library(dplyr)
> data_count <- count(data, c("ID", "Rating"))
> data_count
  ID    Rating    Freq
  12    Good      2
  16    Good      1
  16    Bad       1
  16    Very Bad  1
  34    Very Good 1
>库(dplyr)
>数据计数数据计数
ID额定频率
12好的2
16良好1
16坏的1
非常糟糕
很好

您可以使用
count()
功能,并通过
ID
评级组合进行计数:

> library(dplyr)
> data_count <- count(data, c("ID", "Rating"))
> data_count
  ID    Rating    Freq
  12    Good      2
  16    Good      1
  16    Bad       1
  16    Very Bad  1
  34    Very Good 1
>库(dplyr)
>数据计数数据计数
ID额定频率
12好的2
16良好1
16坏的1
非常糟糕
很好

您可以使用
count()
功能,并通过
ID
评级组合进行计数:

> library(dplyr)
> data_count <- count(data, c("ID", "Rating"))
> data_count
  ID    Rating    Freq
  12    Good      2
  16    Good      1
  16    Bad       1
  16    Very Bad  1
  34    Very Good 1
>库(dplyr)
>数据计数数据计数
ID额定频率
12好的2
16良好1
16坏的1
非常糟糕
很好

您可以使用
count()
功能,并通过
ID
评级组合进行计数:

> library(dplyr)
> data_count <- count(data, c("ID", "Rating"))
> data_count
  ID    Rating    Freq
  12    Good      2
  16    Good      1
  16    Bad       1
  16    Very Bad  1
  34    Very Good 1
>库(dplyr)
>数据计数数据计数
ID额定频率
12好的2
16良好1
16坏的1
非常糟糕
很好

代码中的
唯一
给出了数据集的唯一行,因此
的输出将仅为“1”或“0”,具体取决于组合是否存在。相反,我们可以在整个数据集上应用
,并且
子集
不是“0”的“Freq”

 subset(as.data.frame(table(df1)), Freq!=0)
 #   ID    Rating Freq
 #2  16       Bad    1
 #4  12      Good    2
 #5  16      Good    1
 #8  16  Very Bad    1
 #12 34 Very Good    1

代码中的
unique
给出了数据集的唯一行,因此
的输出将仅为“1”或“0”,具体取决于组合是否存在。相反,我们可以在整个数据集上应用
,并且
子集
不是“0”的“Freq”

 subset(as.data.frame(table(df1)), Freq!=0)
 #   ID    Rating Freq
 #2  16       Bad    1
 #4  12      Good    2
 #5  16      Good    1
 #8  16  Very Bad    1
 #12 34 Very Good    1

代码中的
unique
给出了数据集的唯一行,因此
的输出将仅为“1”或“0”,具体取决于组合是否存在。相反,我们可以在整个数据集上应用
,并且
子集
不是“0”的“Freq”

 subset(as.data.frame(table(df1)), Freq!=0)
 #   ID    Rating Freq
 #2  16       Bad    1
 #4  12      Good    2
 #5  16      Good    1
 #8  16  Very Bad    1
 #12 34 Very Good    1

代码中的
unique
给出了数据集的唯一行,因此
的输出将仅为“1”或“0”,具体取决于组合是否存在。相反,我们可以在整个数据集上应用
,并且
子集
不是“0”的“Freq”

 subset(as.data.frame(table(df1)), Freq!=0)
 #   ID    Rating Freq
 #2  16       Bad    1
 #4  12      Good    2
 #5  16      Good    1
 #8  16  Very Bad    1
 #12 34 Very Good    1

你想做直方图吗?它最终会变成条形图。你想做直方图吗?它最终会变成条形图。你想做直方图吗?它最终会变成条形图。你想做直方图吗?它最终会变成条形图。
count()
dplyr
中-您可能需要明确说明这一点,因为在base中没有base
count
函数-
aggregate
也这样做:
aggregate(list(Freq=dat$ID),dat,FUN=length)
count()
dplyr
中-您可能需要明确说明这一点,因为在base中没有base
count
函数-
aggregate
也这样做:
aggregate(list(Freq=dat$ID),dat,FUN=length)
count()
dplyr
中-您可能需要明确说明这一点,因为在base中没有base
count
函数-
aggregate
也这样做:
aggregate(list(Freq=dat$ID),dat,FUN=length)
count()
位于
dplyr
中-您可能需要明确说明这一点,因为在base中没有base
count
函数-
aggregate
也这样做:
aggregate(list(Freq=dat$ID),dat,FUN=length)