簡體   English   中英

總結R中的一些因素總數

[英]Sum up some factors total counts in R

R的新手!

我有一個調查問卷,回答的人數是0到10。我想加總多少人<=6。多少人7和8。多少人> = 9。

我不得不將問題(Return,Trustworthy ...)轉化為一個因素,以使ggplots在x軸上具有1到10。

uk_super_q<-read.csv("SUPR_Q_UK.csv", header = TRUE)

uk_super_q.Return <- as.factor(uk_super_q$Return)
uk_super_q.Trustworthy <- as.factor(uk_super_q$Trustworthy)
uk_super_q.Credible <- as.factor(uk_super_q$Credible)
uk_super_q.Trustworthy <- as.factor(uk_super_q$Trustworthy)
uk_super_q.Clean.and.Simple <- as.factor(uk_super_q$Clean.and.Simple)
uk_super_q.Easy.to.use <- as.factor(uk_super_q$Easy.to.use)
uk_super_q.Attractive <- as.factor(uk_super_q$Attractive)
uk_super_q.NPS <- as.factor(uk_super_q$NPS)

uk_super_q$Return <- as.factor(uk_super_q$Return)
ggplot(uk_super_q, aes(x = Return)) +
  geom_bar() +
  xlab("Return") +
  ylab("Total Count") +
  labs(fill = "Blah") 
table(uk_super_q.Return)

uk_super_q$Easy.Nav <- as.factor(uk_super_q$Easy.Nav)
ggplot(uk_super_q, aes(x = Easy.Nav)) +
  geom_bar() +
  xlab("Easy.Nav") +
  ylab("Total Count") +
  labs(fill = "Blah") 
table(uk_super_q.Trustworthy)

uk_super_q$Credible <- as.factor(uk_super_q$Credible)
ggplot(uk_super_q, aes(x = Credible)) +
  geom_bar() +
  xlab("Credible") +
  ylab("Total Count") +
  labs(fill = "Blah") 
table(uk_super_q.Credible)

uk_super_q$Attractive <- as.factor(uk_super_q$Attractive)
ggplot(uk_super_q, aes(x = Attractive)) +
  geom_bar() +
  xlab("Attractive") +
  ylab("Total Count") +
  labs(fill = "Blah") 
table(uk_super_q.Attractive)

uk_super_q$Trustworthy <- as.factor(uk_super_q$Trustworthy)
ggplot(uk_super_q, aes(x = Trustworthy)) +
  geom_bar() +
  xlab("Trustworthy") +
  ylab("Total Count") +
  labs(fill = "Blah") 
table(uk_super_q.Trustworthy)

uk_super_q$Clean.and.Simple <- as.factor(uk_super_q$Clean.and.Simple)
ggplot(uk_super_q, aes(x = Clean.and.Simple)) +
  geom_bar() +
  xlab("Clean.and.Simple") +
  ylab("Total Count") +
  labs(fill = "Blah") 
table(uk_super_q.Clean.and.Simple)

uk_super_q$Easy.to.use <- as.factor(uk_super_q$Easy.to.use)
ggplot(uk_super_q, aes(x = Easy.to.use)) +
  geom_bar() +
  xlab("Easy.to.use") +
  ylab("Total Count") +
  labs(fill = "Blah") 
table(uk_super_q.Easy.to.use)

uk_super_q$NPS <- as.factor(uk_super_q$NPS)
ggplot(uk_super_q, aes(x = NPS)) +
  geom_bar() +
  xlab("NPS") +
  ylab("Total Count") 

table(uk_super_q.NPS)

將邏輯語句應用於data.frame返回TRUE / FALSE值的矩陣,這些值在R中分別編碼為1和0。 這使您可以用sum或更有效地使用colSums每列中TRUE值的數量。

colSums(uk_super_q <= 6)
colSums(uk_super_q >= 7 & uk_super_q <= 8)
colSums(uk_super_q >= 9)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM