I would like to create two lists inside another list. Normally I will have to create 50 each one for a state of USA and I'm looking for a way to make it faster.
State <- c("ALABAMA", "ALABAMA", "ALASKA", "ALASKA")
Num <- c(5, 6, 7, 8)
d <- data.frame(State, Num)
uni<-unique(d$State)
data = list(
for(i in 1 : length(uni)){
list[[i]](
name = un[i],
y = summarise(sum(d$Num[D$State==uni[i]])),
drilldown = tolower(un[i])
)
}
)
More specifically I want each list to include the name of the State in Capital letters, y as the sum of the Num and drilldown as the name of the State in non capital letters. The result should be something like:
name="ALABAMA"
y= 11
drilldown="alabama"
name="ALASKA"
y= 15
drilldown="alaska"
Manually it would be like :
data = list(
list(
name = "ALABAMA",
y = 11,
drilldown = "alabama"
),
list(
name = "ALASKA",
y = 15,
drilldown = "alaska"
)
)
which gives a list of 2 lists of 3 objects.
It may be possible without for()so Im open to other suggestions