为数据框中的给定列的每个备用行创建NA

时间:2018-03-22 00:48:44

标签: r dplyr

我想用SKScene替换给定列中各行的重复值。我在这里提供了数据框的一个例子以及列的所需性质。

NA

reprex package(v0.2.0)创建于2018-03-21。

换句话说,我希望# defining the dataframe df <- structure( list( condition = c(4, 4, 6, 6, 8, 8), main = structure( c(2L, 1L, 1L, 2L, 1L, 2L), .Label = c("0", "1"), class = "factor" ), counts = c(8L, 3L, 4L, 3L, 12L, 2L), perc = c( 72.7272727272727, 27.2727272727273, 57.1428571428571, 42.8571428571429, 85.7142857142857, 14.2857142857143 ), `0` = c("27.27%", "27.27%", "57.14%", "57.14%", "85.71%", "85.71%"), `1` = c("72.73%", "72.73%", "42.86%", "42.86%", "14.29%", "14.29%"), `Chi-squared` = c("2.273", "2.273", "0.143", "0.143", "7.143", "7.143"), df = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "1", class = "factor"), `p-value` = c("0.132", "0.132", "0.705", "0.705", "0.008", "0.008"), significance = c("ns", "ns", "ns", "ns", "**", "**") ), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA, -6L), vars = "condition", .Names = c( "condition", "main", "counts", "perc", "0", "1", "Chi-squared", "df", "p-value", "significance" ), indices = list(0:1, 2:3, 4:5), group_sizes = c(2L, 2L, 2L), biggest_group_size = 2L, labels = structure( list(condition = c(4, 6, 8)), class = "data.frame", row.names = c(NA, -3L), vars = "condition", .Names = "condition" ) ) # print the dataframe print(df) #> condition main counts perc 0 1 Chi-squared df p-value #> 1 4 1 8 72.72727 27.27% 72.73% 2.273 1 0.132 #> 2 4 0 3 27.27273 27.27% 72.73% 2.273 1 0.132 #> 3 6 0 4 57.14286 57.14% 42.86% 0.143 1 0.705 #> 4 6 1 3 42.85714 57.14% 42.86% 0.143 1 0.705 #> 5 8 0 12 85.71429 85.71% 14.29% 7.143 1 0.008 #> 6 8 1 2 14.28571 85.71% 14.29% 7.143 1 0.008 #> significance #> 1 ns #> 2 ns #> 3 ns #> 4 ns #> 5 ** #> 6 ** # I want the significance column to be # ns # NA # ns # NA # ** # NA 的每个重复值都替换为significance。我怎样才能做到这一点?如果可能的话,更愿意使用NA回答。

1 个答案:

答案 0 :(得分:3)

这似乎是一种替代操作:

moduleName-pages/index.js

如果需要dplyr,可以通过always.js包装它:

apos.ui.link('manage', 'placement-guide', function () {
      self.manage();
    });

self.manage = function() {
  return self.api('manager-modal', {}, function(data) { ... }