我试图做一些基本的数据操作。我从三个列表开始:
CF.Item <- list("T1Rent", "T2Rent", "Sec.Deposit", "Landlord.Contrib", "Broker.Commission", "NNN", "OpEx", "RE.Tax")
Net.Present.Value <- list(T1Rent.npv, T2Rent.npv, Sec.Deposit.npv, Landlord.Contrib.npv, Broker.Commission.npv, NNN.npv, OpEx.npv, RE.Tax.npv)
Category <- list("Cash IN", "Cash IN", "Cash IN", "Cash OUT", "Cash OUT", "Cash IN", "Cash IN", "Cash IN")
变量xxxx.npv都是数字。 (他们在代码的其他地方计算。)
最终,我想用&#34;类别&#34;来图表xxxx.npv。
我已经尝试了几种不同的方法来将列表操作到矩阵,数据帧,元素......一切。
我也试过这些:
1:总结
by_Cat <- cashcat %>% group_by(Category)
View(by_Cat)
2。 ggplot
p <- ggplot()
p <- p + geom_bar(data = list.npv,
aes(x = Category,
y = Net.Present.Value,
color = CF.Item),
stat = "identity")
p
但我最终总是会遇到关于&#34;类别&#34;。
的错误最后,我搜索了互联网和S.O. 小时,并且无法弄清楚。
我做错了什么/什么是攻击它的好方法?
感谢。
答案 0 :(得分:1)
列表并不适合此目的。向量和数据帧对此更有用。看看:
library(tidyverse)
CF.Item <- list("T1Rent", "T2Rent", "Sec.Deposit", "Landlord.Contrib", "Broker.Commission", "NNN", "OpEx", "RE.Tax")
Net.Present.Value <- as.list(runif(8))
Category <- list("Cash IN", "Cash IN", "Cash IN", "Cash OUT", "Cash OUT", "Cash IN", "Cash IN", "Cash IN")
df <- data_frame(
Category = unlist(Category),
Net.Present.Value = unlist(Net.Present.Value),
CF.Item = unlist(CF.Item))
ggplot(df, aes(x = Category,
y = Net.Present.Value,
color = CF.Item)) +
geom_col()