x is a data.frame
id income age
1 23246 21
1 12455 45
3 24555 31
2 10045 42
I would like to have 3 data frames based on id number
x is a data.frame
id income age
1 23246 21
1 12455 45
3 24555 31
2 10045 42
I would like to have 3 data frames based on id number
split(x,x$id) will produce a list of data frames split on id.
I guess what you need is list2env, i.e.,
xs <- split(x,x$id)
list2env(setNames(xs,paste0("df",names(xs))),
envir = .GlobalEnv)
which creates data frames df1, df2 and df3 in your global environment, such that
> df1
id income age
1 1 23246 21
2 1 12455 45
> df2
id income age
4 2 10045 42
> df3
id income age
3 3 24555 31