我正在尝试修改找到的here代码,以将员工数据从Excel文件导入数据框,然后使用data.tree
包中的as.node函数。
这是我到目前为止编写的代码
library(data.tree)
library(readxl)
baseframe <- read_excel("Test Emplist.xlsx")
baseframe$pathstring <- paste("CompanyName",
baseframe$LastName,
baseframe$FirstName,
sep = "/")
stafflist <- as.Node(baseframe)
正在成功创建数据框。下面是dput表示形式
> dput(head(baseframe))
structure(list(LastName = c("Vasa", "Vasa", "Pras", "Tang", "Sing",
"Vats"), FirstName = c("Evan", "Koma", "Shil", "Hand", "Smri",
"Saur"), pathstring = c("CompanyName/Vasa/Evan", "CompanyName/Vasa/Koma",
"CompanyName/Pras/Shil", "CompanyName/Tang/Hand", "CompanyName/Sing/Smri",
"CompanyName/Vats/Saur")), .Names = c("LastName", "FirstName",
"pathstring"), row.names = c(NA, 6L), class = c("tbl_df", "tbl",
"data.frame"))
但是当我到达stafflist <- as.Node(baseframe)
行时,我收到一条错误消息,说
strsplit(mypath,pathDelimiter,fixed = TRUE的错误:
非字符参数
我猜想as.node函数在某个地方调用了另一个名为strsplit
的函数。我已经尝试过自己运行该功能
strsplit(baseframe$pathstring, "/", fixed = TRUE)
运行没有问题。我不确定为什么as.node函数会引发错误?