首页 > 解决方案 > 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.

标签: rerror-handling

解决方案


推荐阅读