So we want to add person-level summaries of a variable to the right of a data-frame?

  1. Create some data
  1. The dplyr way
  1. The data.table way
  1. The base R way
ID X x
1 -0.5811347 0.2034073
1 -0.3858843 0.2034073
1 0.9627655 0.2034073
1 1.6026897 0.2034073
1 -0.5813995 0.2034073
2 0.6804060 -1.0253115
LS0tCnRpdGxlOiAiUiBOb3RlYm9vayIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQoKU28gd2Ugd2FudCB0byBhZGQgcGVyc29uLWxldmVsIHN1bW1hcmllcyBvZiBhIHZhcmlhYmxlIHRvIHRoZSByaWdodCBvZiBhIGRhdGEtZnJhbWU/IAoKMS4gQ3JlYXRlIHNvbWUgZGF0YSAKCmBgYHtyfQpkIDwtIGRhdGEuZnJhbWUoSUQgPSByZXAoc2VxKDEsNSwxKSwgZWFjaCA9IDUpLAogICAgICAgICAgICAgICAgWCAgPSBybm9ybSgyNSkpCmhlYWQoZCkgJT4lIGtuaXRyOjprYWJsZSgpCmBgYAoKMi4gVGhlIGBkcGx5cmAgd2F5IAoKYGBge3J9CmxpYnJhcnkoZHBseXIpCgpkICU+JQogIGdyb3VwX2J5KElEKSAlPiUgCiAgbXV0YXRlKG1lYW5fb2ZfWCA9IG1lYW4oWCkpICU+JQogIGhlYWQoLikgJT4lIGtuaXRyOjprYWJsZSgpCmBgYAoKMy4gVGhlIGBkYXRhLnRhYmxlYCB3YXkKCmBgYHtyfQpzdXBwcmVzc01lc3NhZ2VzKGxpYnJhcnkoZGF0YS50YWJsZSkpCgpEVCA8LSBhcy5kYXRhLnRhYmxlKGQpCkRUWywgbWVhbl9vZl9YIDo9IG1lYW4oWCksIGJ5ID0gSURdCmhlYWQoRFQpICU+JSBrbml0cjo6a2FibGUoKQpgYGAKCjQuIFRoZSBiYXNlIFIgd2F5IAoKYGBge3J9CmQgPC0gbWVyZ2UoZCwgYWdncmVnYXRlKGQkWCwgYnk9bGlzdChkJElEKSwgRlVOPW1lYW4pLCBieS54ID0gJ0lEJywgYnkueSA9ICdHcm91cC4xJykKaGVhZChkKSAlPiUga25pdHI6OmthYmxlKCkKYGBgCgo=