我想要实现的是:
DF[!!rowSums(DF[-1] <= 0.05, na.rm=TRUE),]
# ID study1 study2 study3
#2 gene2 0.01 NA NA
#3 gene3 NA 0.02 NA
而不是选择输入我想在另一个输入字段中得到它们的总和(这里的总和应该是&#34; 7&#34;。我怎么能这样做?
答案 0 :(得分:1)
你可以这样做。
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
updatesum();
});
function updatesum(){
sum=0;
$("input[name^='audi']").each(function(){
sum+=Number($(this).val());
});
$("#sumofaudi").val(sum);
}
</script>
</head>
<body>
<input name="audi_a4" type="text" value="3" onchange="updatesum();">
<input name="audi_a6" type="text" value="4" onchange="updatesum();">
SUM of AUDI :<input name="sumofaudi" id="sumofaudi" type="text" value="">
<input name="mercedes" type="text" value="5" onchange="updatesum();">
<input name="toyota" type="text" value="2" onchange="updatesum();">
<p>This selector selects all input fields with the attribute name that starts with 'audi'.</p>
</body>
</html>
&#13;
答案 1 :(得分:0)
iTotal = 0;
$("input[name^='audi']").each(function () {
iTotal += parseInt($(this).val(),10);
});
alert(iTotal)