r - Why does one computer throw an error and another not, same code?
问题描述
I have a report that I "flatten" because it comes out of the reporting interface rather kludgy. Something like this, repeating for every employee in the call center:
df <- data.frame(Date = c(NA, 2017, 2018, 2019, 2020), AH = c(NA, 1,2,3,4), NAH = c(NA,5,6,7,8), TH = c(NA,9,10,11,12))
df[1,3] <- "Supervisor: Malcolm Reynolds"
df[1,1] <- "Employee: Jane Cobb"
I have code to remove the Emp name and Super name from the row they are in, and add them to new columns I created earlier by entering the Emp name in each row for that person. Like this:
l <- grep("Employee:", adh$Date) ##find emp/super rows
m <- l[-1] ##new list without first row
m <- append(m,nrow(adh)) ##add last row to new list
##fill in new columns, column 8 is EmpName, 9 is SuperName
for (i in 1:length(l)) {
adh[as.integer(l[i]):as.integer(m[i]),8] <- adh[as.integer(l[i]),1]
adh[as.integer(l[i]):as.integer(m[i]),9] <- adh[as.integer(l[i]),3]
}
On my machine, everything works fine, it's all base package code. My employee runs this, and on the first line inside the for loop, it throws this error:
Error: Assigned data adh[as.integer(l[i]), 1]
must be compatible with existing data.
i Error occurred for column Emp_Name
.
x Can't convert to .
He just installed R and RStudio, I have a ton of other packages installed. I have no idea why this is happening for him and not me. Note, I'm not an under the hood user.
解决方案
推荐阅读
- reactjs - 想安装反应但面临生成错误
- r - 从R中的矩阵中随机删除一些数字数据?
- nestjs - 我们如何访问控制器nestjs
- flutter - DropdownButtonFormField 不显示下拉菜单项
- javascript - 迭代对象及其子对象的属性
- docker - 远程服务器上的 Docker 上下文“来自守护程序的错误响应:无效的卷规范”
- mysql - linux中的MySql问题。启动mysql.service失败:未找到单元mysql.service
- python - 提高python中的递归效率
- python - 无法通过证书和 Python 请求完成 SSL 连接
- javascript - Javascript setTimeout 随机输出