我希望从已经拆分的字符串索引单词data1 <- c("11:14", "17:27", "25:34", "39:17", "39:59", "42:32", "50:15", "50:53", "64:22", "67:39")
data2 = sapply(strsplit(data1,":"), # from http://stackoverflow.com/a/5187350/7128934
function(x) {
x <- as.numeric(x)
x[1]+x[2]/60
}
)
difference = list()
for (i in 1: (length(data1) - 1)) {
difference[i] = data2[i+1] - data2[i]
}
。然后我想在索引单词之前打印第6个字符串。
'OPEN'
我正在寻找的输出是>>> details = ['Serial#', ':', 'xxx00', 'LV', ':', '0', 'SL', ':',
'0', 'CL', ':', '0', 'TYPE', ':', 'OPEN', etc...]
>>> num = details.index('OPEN')
。
答案 0 :(得分:2)
当然是&#34;索引&#34;索引序列(如列表)可以是任何表达式,包括减法:
num = details[details.index('OPEN') - 6]