因子水平的功能

时间:2019-04-03 18:40:01

标签: r dataframe operators which

我想将# Create cursor associated with connection cursor=conn.cursor() cursor_select = conn.cursor() cursor_insert = conn.cursor() if conn: print('***** Connected to DCPWDBS289 *****') select_str="SELECT TOP 5 Incident_ID,Incident_Type,Priority FROM incidents_all WHERE incidents_all.Status NOT IN ('Closed','Resolved')" cursor_select.execute(select_str) while True: row = cursor_select.fetchone() if not row: break print(' Row: ', row) IncIncident_ID = row[0] # Float IncIncident_Type = row[1] # Str IncPriority = row[2] # Str sql = """EXEC ITSM.dbo.ITSM_LOAD @IncIncident_ID=?, @IncIncident_Type=?,@IncPriority=?""" params = ('IncIncident_ID','IncIncident_Type','IncPriority') cursor_insert.execute(sql,params) del cursor_insert cursor.commit() conn.close() 的{​​{1}}函数与which一起使用。如果我按列使用它会产生正确的结果。但是整个arr.ind = TRUE我都无法理解。

注意:我编辑了代码。另外,预期的输出将添加到代码中。

MWE:

data.frame

1 个答案:

答案 0 :(得分:0)

这是一种方法:

x = as.matrix(df) %in% c("a", "b")
cbind(row(df)[x], col(df)[x])
#      [,1] [,2]
# [1,]    1    1
# [2,]    2    1
# [3,]    3    1
# [4,]    1    2
# [5,]    5    2

如果您打算替换这些值,则在整个数据帧中逐列进行可能会最有效(不使用此结果)。