【发布时间】:2019-01-14 12:08:39
【问题描述】:
给出了员工的角色和该角色的开始日期。名为“角色”的数据框包含该名称。开始日期应填写用户为该特定名称提供的值,其余列应填写“-”
roles <- data.frame(character(),character(),character(),character(),
stringsAsFactors = FALSE)
roles[1, ] <- ifelse(names(roles) == a,sd, "-")
roles
newrow = data.table(`Manager_start` = roles[1,4],
`VP_start` = roles[1,3],
`AP_start` = roles[1,2],
`P_start` = roles[1,1])
dbWriteTable(conn = con,"table_name",newrow,append=TRUE,row.names=FALSE)
预期结果是 Manager 列的值应为“12/12/12”,而其他列的值应为“-”。但是随机值会存储在数据库中,例如“17914”
【问题讨论】:
-
将
stringsAsFactors = FALSE添加到您的data.frame通话中,然后执行roles[1, ] <- ifelse(names(roles) == a,sd, "-") -
它运作良好.. 谢谢
-
使用 if(roles[i] == a) 代替 if(roles[i] = a) ?我无法编辑它,因为它少于 6 个字符。
标签: r