我正在尝试删除闪亮数据表中的标题行,是否有人知道是否有这样做的选项?
最小的例子:
#SERVER.R
output$myTable <- renderDataTable({
datatable(dataset, rownames = FALSE, selection = 'none', options = list(dom = 't'))
})
#UI.R
dataTableOutput('myTable')
Run Code Online (Sandbox Code Playgroud) 我需要根据跨多个列的条件对data.table进行子集化,然后对结果执行操作.
一个简单data.table的最小例子:
x <- data.table(id=c(1, 2, 3, 4), colour1 = c('red', 'green', 'green', 'blue'),
colour2 = c('yellow', 'red', 'blue', 'black'),
colour3 = c('blue', 'black', 'red', 'yellow'),
score = c(0.7, 0.9, 0.2, 0.35))
Run Code Online (Sandbox Code Playgroud)
然后我想找到包含颜色'yellow'的任何行的最高分数:
max_score <- max(x[colour1 == 'yellow' | colour2 == 'yellow' | colour3 == 'yellow']$score)
Run Code Online (Sandbox Code Playgroud)
在这个例子中,上面的代码工作正常但是有更好的方法来检查多个列的这种情况吗?在实践中,表格会更大,列数可以改变,所以我想动态地这样做.
我有一个大字符串和一个搜索字符串列表,并希望构建一个布尔列表,指示每个搜索字符串是否存在于大字符串中.在Python中执行此操作的最快方法是什么?
下面是一个使用天真方法的玩具示例,但我认为这可能是一种更有效的方法.
例如,下面的示例应返回[1,1,0],因为测试字符串中存在"hello"和"world".
def check_strings(search_list, input):
output = []
for s in search_list:
if input.find(s) > -1:
output.append(1)
else:
output.append(0)
return output
Run Code Online (Sandbox Code Playgroud)
search_strings = ["hello", "world", "goodbye"]
test_string = "hello world"
print(check_strings(search_strings, test_string))
r ×2
data.table ×1
dataframe ×1
datatable ×1
dt ×1
performance ×1
python ×1
search ×1
shiny ×1
string ×1