我有一个数据框,如:
df <- data.frame(
ID = c('123','124','125','126'),
Group = c('A', 'A', 'B', 'B'),
V1 = c(1,2,1,0),
V2 = c(0,0,1,0),
V3 = c(1,1,0,3))
返回:
ID Group V1 V2 V3
1 123 A 1 0 1
2 124 A 2 0 1
3 125 B 1 1 0
4 126 B 0 0 3
我想返回一个表,表明变量是否在组中表示:
Group V1 V2 V3
A 1 0 1
B 1 1 1
为了计算每组中不同变量的数量。
答案 0 :(得分:2)
我们可以使用@Override
protected void onPostExecute(String result){
super.onPostExecute(result);
try {
JSONObject jsonObject = new JSONObject(result);
JSONObject weatherDatas = new JSONObject(jsonObject.getString("main"));
double temperature = Double.parseDouble(weatherDatas.getString("temp"));
int tempIn = (int) (temperature*1.8-459.67);
String placeName = (String) jsonObject.get("name");
MainActivity.tempeartureTextView.setText("" + tempIn);
MainActivity.placeTextView.setText(placeName);
Log.i("it made it", "to end of DownloadTask");
//using http://samples.openweathermap.org/data/2.5/weather?zip=94040,us&appid=b1b15e88fa797225412429c1c50c122a1 with zip code
} catch (Exception e) {
e.printStackTrace();
}
}
t_employee
或使用base R
aggregate(.~Group, df[-1], function(x) as.integer(sum(x)>0))
# Group V1 V2 V3
#1 A 1 0 1
#2 B 1 1 1
rowsum
或base R
+(rowsum(df[-(1:2)], df$Group)>0)
# V1 V2 V3
#A 1 0 1
#B 1 1 1
by
答案 1 :(得分:0)
你试过吗
unique(group_by(mtcars,cyl)$cyl).
Output:[1] 6 4 8