> result <- left_join(file1, file2, by = "ID") Error in `left_join()`: ! Input columns in `x` must be unique. ✖ Problem with `ID`. Run `rlang::last_trace()` to see where the error occurred. >
时间: 2024-01-26 21:03:19 浏览: 186
这个错误提示说明在进行 left_join 操作时,数据框中的某些列在名称上存在冲突。在这种情况下,需要检查两个数据框中是否存在相同名称的列,并对列名进行修改以消除名称冲突。
你可以按照以下步骤进行修改:
1. 读取第一个 CSV 文件,并将第一列的列名修改为 ID:
```
file1 <- read.csv("【1】output_summary.csv")
colnames(file1)[1] <- "ID"
```
2. 读取第二个 CSV 文件,并将其中与第一个 CSV 文件中列名相同的列重命名:
```
file2 <- read.csv("fullnamelineage.csv")
colnames(file2)[1] <- "ID2" # 将第一列的列名修改为 ID2
```
3. 进行 left_join 操作并将结果保存为名为 blastx 的 CSV 文件:
```
library(dplyr)
# 将 file2 的数据根据 ID 列与 file1 进行左连接
result <- left_join(file1, file2, by = c("ID" = "ID2"))
# 将结果保存为名为 blastx 的 CSV 文件
write.csv(result, "blastx.csv", row.names = FALSE)
```
在这个示例中,我们首先读取了第一个 CSV 文件,然后使用 `colnames()` 函数修改了第一列的列名为 ID。然后,我们读取了第二个 CSV 文件,并使用 `colnames()` 函数将其中与第一个 CSV 文件中列名相同的列重命名为 ID2。最后,我们使用 `left_join()` 函数将两个数据框根据 ID 列进行左连接操作后得到了结果,并使用 `write.csv()` 函数将结果保存为名为 blastx.csv 的文件。
阅读全文
相关推荐





look54.php:
<?php
session_start();
require "../db54.php";
if(!isset($_SESSION["username"])) {
header("Location: ../login54.php");
exit;
}
$user = $_SESSION["username"];
?>
<!DOCTYPE html>
<html>
<head>
<title>我的购物车</title>
<style>
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px; text-align: left; border-bottom: 1px solid #ddd; }
img { max-width: 100px; }
</style>
<script>
function openme(row) {
row.style.backgroundColor = "#FFFFCC";
}
function closeme(row) {
row.style.backgroundColor = (row.rowIndex % 2 == 1 ? "#F0F0F0" : "");
}
function op(button, id) {
// Implement quantity increase/decrease logic
}
function select_all() {
// Implement select all checkboxes
}
function reset_all() {
// Implement reset all checkboxes
}
function delete_all() {
// Implement delete selected items
}
function na() {
return confirm("确定要移除该商品吗?");
}
function op(t,id) {
value=t.value; //按钮上显示的文字
if(value=='+') { //带参数跳转,兼容Google.ie
parent.top.window.location="look54.php?op=add&id="+id;
}
if(value=='-') {
parent.top.window.location="look54.php?op=sub&id="+id;
}
}
</script>
</head>
<body>
我的购物车
<?php
// 显示当前用户信息 - 统一使用username
if(isset($_SESSION['username'])) {
echo "查看购物车 | 当前用户:" . htmlspecialchars($user) . "";
?>
<form name="cartForm" method="post">
选择
商品名称
商品图片
订阅数量
单价
操作
<?php
// 处理"拿掉该商品"超链接删除
if(isset($_GET['id']) && $_GET["op"]=="移除") {
$id = $_GET['id'];
$sql = "DELETE FROM dingdan54 WHERE id = $id";
if($db54->write($sql)) {
echo "<script>alert('拿掉商品成功!')</script>";
} else {
echo "<script>alert('拿掉商品失败!')</script>";
echo "<script>location.href('look54.php')</script>";
}
}
// 处理增减按钮+-操作
if(isset($_GET["op"])) {
$op = $_GET["op"];
$id = $_GET['id'];
// 获取当前数量
$sql = "SELECT * FROM dingdan54 WHERE id = $id";
$result = $db54->read($sql);
if(count($result) > 0) {
$current_num = $result[0]['num'];
if($op == "add") {
$new_num = $current_num + 1;
} elseif($op == "sub" && $current_num > 1) {
$new_num = $current_num - 1;
} else {
$new_num = $current_num;
}
// 更新数量
$update_sql = "UPDATE dingdan54 SET num = $new_num WHERE id = $id";
$db54->write($update_sql);
}
}
// 处理"拿掉选中商品"按钮
if(isset($_GET["str"])) {
$ids = explode("|", trim($_GET["str"], "|"));
foreach($ids as $id) {
if(is_numeric($id)) {
$sql = "DELETE FROM dingdan54 WHERE id = $id";
$db54->write($sql);
}
}
echo "<script>alert('拿掉商品成功!')</script>";
echo "<script>location.href('look54.php')</script>";
}
// 显示购物车
$cart_sql = "SELECT dingdan54.id AS id, sp54.name AS name, sp54.photo AS photo, SUM(dingdan54.num)
AS total_num, sp54.money AS money FROM sp54
JOIN dingdan54 ON sp54.id = dingdan54.sp_id
WHERE sp54.id = dingdan54.sp_id AND dingdan54.user = '$user' AND dingdan54.flag = 0
GROUP BY sp54.id, sp54.name, sp54.photo, sp54.money";
$cart_result = $db54->read($cart_sql);
$n = count($cart_result);
if ($n == 0) {
echo "购物车是空的! ";
}else{
for ($i = 0; $i < $n; $i++) {
$item = $cart_result[$i];
echo "";
echo "<input type='checkbox' name='flag' value='{$item['id']}'> ";
echo "{$item['name']} ";
echo "![]()
";
echo "<input type='button' name='enter' value='-' onclick='op(this, {$item['id']})'>
<input type='text' name='num{$item['id']}' readonly size='3'
style='text-align:center' value='{$item['total_num']}'>
<input type='button' name='enter' value='+' onclick='op(this, {$item['id']})'> ";
echo "{$item['money']}元 ";
echo "
移除该商品 ";
echo " ";
}
}
?>
<input type="button" name="enter" value="全选" onclick="select_all()">
<input type="button" name="enter" value="全部取消" onclick="reset_all()">
<input type="button" name="enter" value="删除选中商品" onclick="delete_all()">
<?php
$total_sql = "SELECT sp54.money AS money, dingdan54.num AS num
FROM sp54, dingdan54
WHERE sp54.id = dingdan54.sp_id AND dingdan54.user = '$user'
AND dingdan54.flag = 0";
$total_result = $db54->read($total_sql);
$sum = 0;
foreach ($total_result as $item) {
$sum += $item["money"] * $item["num"];
}
echo "应付金额:¥";
echo $sum . " 元";
echo " | 去付款";
?>
</form>
继续购物
<?php } ?>
</body>
</html>
l54.php:
<?php
include('../db54.php');
session_start();
$user_id=$_SESSION["id"]?? 0;
$sql="select * from user54 where id='$user_id'";
$result=$db54->read($sql);
$username=$result[0]["username"];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>信安28班54何雨霏PHP实训</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="all,follow">
</head>
<body>
Nathan AndrewsWeb Developer
BD
Main
何雨霏的留言板
实训页面1
实训页面2
实训页面3
Example dropdown
admin
查看购物车
后台管理
Login page
Demo
6 New
Second menu
admin
查看购物车
后台管理
<?php
?>
信安28班54何雨霏PHP实训 <?php echo $username; ?>
12
You have 6 new messages
4 minutes ago
You have 2 followers
4 minutes ago
Server Rebooted
4 minutes ago
You have 2 followers
10 minutes ago
view all notifications
10
Jason Doesent you a direct message3 days ago at 7:58 pm - 10.06.2019
Frank Williamssent you a direct message3 days ago at 7:58 pm - 10.06.2019
Ashley Woodsent you a direct message3 days ago at 7:58 pm - 10.06.2019
Read all messages
English
German
French
Logout
<?php require "daohang54.php"; ?>
<?php require "look54.php"; ?>
<script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
<script src="vendor/popper.js/umd/popper.min.js"> </script>
<script src="https://www.jq22.com/jquery/bootstrap-4.2.1.js"></script>
<script src="js/grasp_mobile_progress_circle-1.0.0.min.js"></script>
<script src="vendor/jquery.cookie/jquery.cookie.js"> </script>
<script src="vendor/chart.js/Chart.min.js"></script>
<script src="vendor/jquery-validation/jquery.validate.min.js"></script>
<script src="vendor/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="js/charts-home.js"></script>
<script src="js/front.js"></script>
</body>
</html>
页面能显示look54的内容,不能显示l54的框架












