I am a bit confused here and not able to find a good answer.
I have a dataframe that I am trying to aggregate:
dt <- data.frame(age=rchisq(20,10),group=sample(1:2,20,rep=T))
When I aggregate this dataframe and save it to a new dataframe it only saves 2 observations and 2 variables to the global environment:
ag<-aggregate(age ~ group, dt, function(x) c(mean = mean(x), sd = sd(x)))
group age
1 1 9.119008
2 2 9.740361
Namely the columns group and age. When I perform this action directly in the console it prints three columns namely group age.mean and age.sd as supposed to:
aggregate(age ~ group, dt, function(x) c(mean = mean(x), sd = sd(x)))
group age.mean age.sd
1 1 9.119008 3.611732
2 2 9.740361 4.163281
Even when printing the global environment dataframe to the console with ag it prints all three columns. Why does this third column not show up in the global environment? How can I get it there?