r - FUN(X[[i]], ...) 中的错误:带刺的参数的“类型”(字符)无效
问题描述
我在加载数据时遇到问题。如果有人可以看看,那将不胜感激!
代码
data <- structure(list(Date = c("2-Nov-20", "2-Nov-20", "2-Nov-20", "2-Nov-20",
"2-Nov-20", "2-Nov-20"), Cycle = c(1L, 1L, 1L, 1L, 1L, 1L), Route = c("T1",
"T1", "T1", "T1", "T1", "T1"), Waypoint = c("FQ1120", "FQ1121",
"FQ1122", "FQ1123", "FQ1127", "FQ1125"), Latitude = c("1.326983012",
"1.327218041", "1.327946009", "1.328284973", "1.329542007", "1.329018977"
), Longitude = c("103.659741", "103.659496", "103.659467", "103.65963",
"103.660734", "103.659631"), Sampling.point = c("T01_01", "T01_01",
"T01_01", "T01_02", "T01_20", "T01_02"), Latitude.1 = c(NA, NA,
NA, NA, NA, NA), Longitude.1 = c(NA, NA, NA, NA, NA, NA), Time..24h. = c("1947",
"1948", "1950", "1952", "2003", "1957"), Common.name = c("Wild pig",
"Red junglefowl", "Changeable lizard", "Savanna nightjar", "Changeable lizard",
"Yellow-vented bulbul"), Taxon = c("Mammal", "Bird", "Reptile",
"Bird", "Reptile", "Bird"), Scientific.name = c("Sus scrofa",
"Gallus gallus", "Calotes versicolor", "Caprimulgus affinis",
"Calotes versicolor", "Pycnonotus goiavier"), Global.status..IUCN.CITES. = c("Least Concern",
"Least Concern", "Not Assessed", "Least Concern", "Not Assessed",
"Least Concern"), Local.status..Davison.et.al...2008..Jain.et.al...2018.for.butterflies..Soh.et.al...2019.for.odonates. = c("Not Assessed",
"Endangered", "Not Assessed", "Not Assessed", "Not Assessed",
"Not Assessed"), Quantity = c("1", "1", "1", "1", "3", "7"),
Observation.type..seen.heard.caught.scat.other.signs. = c("Seen",
"Seen", "Seen", "Heard", "Seen", "Seen"), Photo.no. = c("",
"", "", "", "", ""), Survey.method..targeted.incidental.point.count.trapping. = c("Incidental",
"Incidental", "Targeted", "Targeted", "Targeted", "Targeted"
), Remarks = c("", "", "", "", "", ""), abundance = c(1,
1, 1, 1, 1, 1)), row.names = c(NA, 6L), class = "data.frame")
data$abundance <- 1 #add a column of 1
data.matrix <- xtabs(Quantity~Scientific.name+Sampling.point, data=data)
错误代码:
Error in FUN(X[[i]], ...) : invalid 'type' (character) of argument
不知道为什么会这样?任何帮助表示赞赏!
解决方案
我们需要“数量”为数字。是character
课
data$Quantity <- as.numeric(data$Quantity)
xtabs(Quantity~Scientific.name+Sampling.point, data=data)
# Sampling.point
#Scientific.name T01_01 T01_02 T01_20
# Calotes versicolor 1 0 3
# Caprimulgus affinis 0 1 0
# Gallus gallus 1 0 0
# Pycnonotus goiavier 0 7 0
# Sus scrofa 1 0 0
推荐阅读
- javascript - VueJS Axios JSON 切片/过滤器不是函数
- php - file_get_contents(includes_url('/js/jquery/jquery.js')); 不工作
- php - 使每一行 DataTables 成为 ID 的超链接
- python - PyCharm:独立/相关项目配置
- java - Spring security with xml config NoSuchBeanDefenitionException 没有 AuthenticationManager 类型的限定 bean
- tensorflow - 使用 Dataset API 从 TFrecord 读取图像并在 Jupyter 笔记本上显示它们
- c# - 如何从 C# 中的 Drodownlist 中获取值
- search - Flutter Firestore Query Listen - 无法从 Listen 中引用变量
- excel - .找到从范围中读取多个项目的最佳/最佳实践方式
- javascript - 计算器:字符串转换为数学运算 (JavaScript)