我需要使用 cat 函数向 CSV 添加新行。请你们帮帮我好吗?我对 R 的了解有限。
这是文件“name1.csv”,系统要求我将我的姓名和学生 ID 添加到前几行。
homework1 <- data.frame (homework1,Total)
homework1 <- data.frame (homework1, Commission)
# Create output file name using name1. All your output will go to this file.
sink("name1.csv")
# send the output to the csv file you just created
write.csv(homework1, file = "name1.csv")
# delete first column of the csv file
# Use cat function to write your name (First Last). This will be Row 1 of csv file.
cat(file = "name1.csv", "Ibra", "\n", sep = ",", append=TRUE, row.names(F))
如果你想知道如何使用一个函数,你可以调用help
其上的函数:
help(cat)
Usage
猫(...,文件=“”,sep=“”,填充=FALSE,标签=NULL,
追加=假)
论据
...
它还在继续。
默认情况下,Cat 将写入接收器。因此,如果您希望您的名字在文件中首先出现。从猫你的名字开始:
sink("name1.csv")
cat("Ibra Lastname\n") # sink is set, so file is not needed
write.csv(homework1)
请注意,这将使 csv 文件无效;第一行将是单个字符串,其余行将具有逗号分隔的值,无论 homework1 的形状是什么。这项作业对我来说意义不大。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)