I have a simple dataframe in the format as follows:
df <- data.frame(var1 = c(1, 1, 1, 2, 2, 2),
var2 = c(144, 156, 160, 123, 138, 170))
I want to create a vector (just call it vec) with indexes of the unique values of var1 in my dataframe and then at that index assign the values in var2 that correspond to its value of var1. So, var1 is the id or grouping variable in my data. The desired result would look like the following:
vec
"144, 156, 160", "123, 138, 170"
vec[1]
"144, 156, 160"
vec[2]"123, 138, 170"
aggregate(var2~var1, df, toString)? The second column isvec.