如何为每个循环添加到我的对象名称数字

时间:2017-12-26 22:31:55

标签: java set

让我说我有

# create example data 
d1 <- data.frame(month = c(1:3), val = c(1,2,5))
d2 <- data.frame(month = c(1:5), val = c(1,2,5,6,8))
df_list <- list(d1, d2)

> df_list 
[[1]]
  month val
1     1   1
2     2   2
3     3   5

[[2]]
  month val
1     1   1
2     2   2
3     3   5
4     4   6
5     5   8

mymonths <- c("JAN","FEB","MAR",
              "APR","MAY","JUN",
              "JUL","AUG","SEP",
              "OCT","NOV","DEC")

df_list2 <- lapply(df_list , function(x) {
  x[,1] <- mymonths [ x[,1] ]
  })

> df_list2 
[[1]]
[1] "JAN" "FEB" "MAR"

[[2]]
[1] "JAN" "FEB" "MAR" "APR" "MAY"

我想添加到这个集合cat0,cat1,cat2,cat3

 public static Set<Cat> createCats() {
    HashSet<Cat> result = new HashSet<Cat>();
     for (int i = 0; i < 4; i++) {
         Cat cat= new Cat();
          result.add(cat);
     }

0 个答案:

没有答案