You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用R语言MASS包绘图及读取Tick_2017_map.csv报错问题咨询

问题解决说明

报错原因

  • 文件读取失败:读取时误将.csv后缀写为.txt,且未指定data子目录路径,R无法在工作目录根目录找到目标文件
  • 后续对象不存在报错:均为文件读取失败未生成map.2对象导致的连锁报错,同时原后续操作存在两处拼写错误:specoes应为species,输出文件名Sangeineus应为Sanguineus

完整可运行代码

# 原有代码无需修改部分
#Importing and Exporting Data
  #Get the demo data that comes with the "MASS" package
getwd()
setwd("~/&")
setwd("College/2021-2022/Fall 2021/Programming for Biologists BIOM 419/R Project 1/")

install.packages("MASS")
library(MASS)
data()

#Plot body weight (kg) vs brain weight (g) and label the axes and add a title
plot(mammals$body, mammals$brain, col="RED", pch=15, cex=1,
     xlab="Body Weight", ylab="Brain Weight", 
     main="Plot of Brain Wt. as a Function of Body Wt.")
mammals1<-mammals[order(mammals$body),]
mammals1$logbody<-log(mammals1$body)
mammals1$logbrain<-log(mammals1$brain)

# ----------------------新增/修正部分----------------------
# 作业要求1:绘制对数转换后的体重与脑重散点图
plot(mammals1$logbody, mammals1$logbrain, col="BLUE", pch=16, cex=1.2,
     xlab="Log-transformed Body Weight", ylab="Log-transformed Brain Weight", 
     main="Log-transformed Brain Weight vs Body Weight")

# 作业要求2:读取data子文件夹下的Tick_2017_map.csv文件
# 若运行后仍提示文件不存在,可先运行 list.files("./data") 检查data目录下的文件名是否匹配
map.2 <- read.csv("./data/Tick_2017_map.csv")

# 后续操作修正拼写错误后可正常运行
str(map.2)
summary(map.2$species)
# 修正列名拼写错误 specoes -> species
map.s <- map.2[map.2$species == "sanguineus", c(1:8)]
table(map.s$species)
# 修正输出文件名拼写错误 Sangeineus -> Sanguineus,csv格式文件建议用.csv后缀
write.csv(map.s, file = "Sanguineus.csv")

内容的提问来源于stack exchange,提问作者user17021801

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 08:06:05