我有两个表,Catdata和ElementData。如果ElementData$Match
为Catdata$category
或fiction
或suspense
,我希望thriller
返回1,否则返回0。如果没有循环,我该怎么做?
Catdata
Element Category
abc123 thriller
abc123 horror
def456 fiction
def456 suspense
def456 thriller
pqr789 romance
pqr789 fiction
xyz123 thriller
elementData中
Element Match
def456
abc123
xyz123
pqr789
答案 0 :(得分:0)
如果ElementData$Match
的{{1}}对应Catdata$category
的{{1}}的任何值与Catdata$Element
匹配,则library(dplyr)
## Create lookup table of all elements matching the criteria:
matchData <- Catdata %>%
group_by(Element) %>%
dplyr::summarise(Match = (Category %in%
c("fiction", "suspense", "thriller")) %>%
any %>% as.integer)
## Merge your second table with the lookup table
ElementData <- ElementData %>% left_join(matchData, by = "Element")
返回1,您可以执行以下操作:
`<?php for($i=1; $i<=30; $i++){ ?>
<div class="form-group c">
<div class="col-xs-12 col-sm-12">
<div class="input-group">
<select name="istbs_code_<?php echo $i; ?>" class="dropchange col-xs-12 col-sm-6 required-field form-control" id="istbs_code_<?php echo $i; ?>" placeholder="ISTBS Code" tabindex="1" data-style="form-control">
<option value="">Select Option</option>
</select>
</div>
</div>
</div>
<?php } ?>`
$(document).on("change",".dropchange ",function(){
var thisid=this.id;
var json = {};
var abc = json['iat_code_1'] = $(this).val();
var request = callajax(thisid);
});
function callajax(thisid){
$.ajax({
url: "<?php echo base_url($controller.'/get_product_attributes'); ?>",
type: "POST",
data: json,
dataType: "html",
success : function(response){
$("#"+thisid).html(response);
}
});
}