我有一个data.table,我想对其进行过滤和聚合,其中要分组的某些列是固定的,而有些则来自函数参数。 这种组合会产生一条错误消息。
这是一个简单且可复制的示例
<Grid>
<Border ClipToBounds="True" Background="Beige" Width="200" Height="200">
<TextBlock TextWrapping="Wrap" FontSize="20" Text="AB CD EF GH IG KL MN OP QR ST UV WX YZ">
<TextBlock.RenderTransform>
<ScaleTransform ScaleX="1" />
</TextBlock.RenderTransform>
</TextBlock>
</Border>
</Grid>
我不明白为什么dt <- data.table(A = rnorm(10),
B = sample(c("1", "2"), 10, replace = TRUE),
C = sample(c("1", "2"), 10, replace = TRUE))
col1 <- "B"
dt[B == "1", mean(A), by = .(get(col1))] # works
dt[B == "1", mean(A), by = .(C, get(col1))] # does not work
dt[, mean(A), by = .(C, get(col1))] # works
dt[B == "1", mean(A), by = c("C", col1)] # works and returns the intended result
dt[B == "1"][, mean(A), by = .(C, get(col1))] # works and returns the intended result
链接时dt[B == "1", mean(A), by = .(C, get(col1))]
不起作用。
答案 0 :(得分:1)
一个原因可能是因为在全局环境中定义<div class="form-group col-md-6">
<?php if($saved_image != ''): ?>
<div class="col-md-6"><!-- This is EDITED-->
<img class="img-thumb" src="<?=$saved_image;?>" alt="saved image" />
<br>
<a href="products.php?delete_image=1&edit=<?=$edit_id;?>" class="text-danger">Delete Image</a>
</div> <!-- This Is ADDED NEWLY-->
<div class="col-md-6"> <!-- This Is ADDED NEWLY-->
<!-- Start Another image 2 -->
<img class="img-thumb" src="<?=$saved_image;?>" alt="saved image" />
<br>
<a href="products.php?delete_image=1&edit=<?=$edit_id;?>" class="text-danger">Delete Image</a>
<!-- End Another image 2 -->
</div> <!-- This Is ADDED NEWLY-->
</div>
<!-- If Edit Happen - End -->
<?php else:?>
<!-- If image empty or user first time add product[data is not saved in the database] -->
<label for="photo">Product Photo:</label>
<input class="form-control" type="file" name="photo[]" id="photo" multiple>
<?php endif;?>
时将col1 <- "B"
分配给B
,因此函数col1
会查找get
(未定义)。