我有一个具有唯一标识符的数据集,例如下面的
@DataProvider(name = "test")
public Object[][] testDP() throws Exception {
Object[][] arrayObject = getExcelData("TestData.xlsx", "TestData", "testName");
return arrayObject;
}
@Test(dataProvider = "test", groups = {"sanity"})
public void testMethod(String testName, String logisticsHandler) {
System.out.print(testName + "\n");
setUpdateLogisticsHandler(logisticsHandler);
updateLogisticsHandler(context.getAuthToken(),context.getQuoteIdForRfq());
}
我想创建一个具有年龄的分类变量,例如“0 - 4年”,“5 - 14年”,“15 - 60年”和“61及以上”。 然后生成一个新变量,显示数据的摘要(聚合),使数据看起来像
Questionnaire id Age
Q1 40
Q1 1
Q1 7
Q2 40
Q2 70
Q2 30
Q3 8
Q3 7
Q3 4
答案 0 :(得分:1)
你可以这样做:
df$range <- as.vector(cut(df$Age, c(0,4,14,60,Inf)
, labels = c("0-4", "5-14","15-60","61 and above")))
xtabs(~id+range,df)
# range
# id 0-4 15-60 5-14 61 and above
# Q1 1 1 1 0
# Q2 0 2 0 1
# Q3 1 0 2 0
数据强>
df <- data.frame(id=c("Q1","Q1","Q1","Q2","Q2","Q2","Q3","Q3","Q3")
,Age=c(40,1,7,40,70,30,8,7,4),stringsAsFactors = F)