仅当“ if”''''条件已验证
我正在努力为我的论文撰写有关银行的数据框架! 特别是我必须从数据集中选择一些行。
- 是否有2个等名
- 我检查“公司名称”列中
- 首先, 。
最后一点是我遇到问题的一点。我认为我正在按照如何将行分配到数据集的所有说明,但仍然找不到解决方案,希望您能帮助我!
data <- data.frame()
for (i in 1:nrow(total)) {
for (j in 2:nrow(total)){
if(total$Company_name[i]==total$Company_name[j] & total$Consolidation_code[i] == "U2")
{data <- total[i,]}
else if (total$Company_name[i]==total$Company_name[j] & total$Consolidation_code[i] == "C2")
{data <- total[i,]}
else if (total$Company_name[i]==total$Company_name[j] & total$Consolidation_code[i] == "C1")
{data <- total[i,]}
else if (total$Company_name[i]==total$Company_name[j] & total$Consolidation_code[i] == "U1")
{data <- total[i,]}
}
}
这是我写的代码。.请让我知道您是否可以发现我的错误,如果您知道一种更简单的方法来编码我的问题,请告诉我。 提前致谢。
更新现在此代码有效,但是它仅为新数据集分配了1行..您能发现问题吗?
I'm trying to work on a dataframe on R about banks for my thesis!
In particular I have to select some rows from my dataset.
- First I check if there are 2 equal name in the column "company name"
- Second I check which is the "consolidation code" in the column
- Lastly, depending on the consolidation code, I try to assign the row of my dataset to a new dataset.
The last point is the one where I'm having problems.. I think I'm following all the instructions from how to assign a row to a dataset, but still cannot find a solution and I hope you can help me!
data <- data.frame()
for (i in 1:nrow(total)) {
for (j in 2:nrow(total)){
if(total$Company_name[i]==total$Company_name[j] & total$Consolidation_code[i] == "U2")
{data <- total[i,]}
else if (total$Company_name[i]==total$Company_name[j] & total$Consolidation_code[i] == "C2")
{data <- total[i,]}
else if (total$Company_name[i]==total$Company_name[j] & total$Consolidation_code[i] == "C1")
{data <- total[i,]}
else if (total$Company_name[i]==total$Company_name[j] & total$Consolidation_code[i] == "U1")
{data <- total[i,]}
}
}
This is the code I wrote.. please let me know if you can spot my mistake and let me know if you know an easier way to code my problem.
Thanks in advance.
UPDATE now this code works, but it only assign 1 row to the new dataset.. can you spot the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论