0

I'm trying to create a vector using c(). I have a column of CIK numbers that I want to put into that vector by a year variable column.

df --> my dataframe name 

df$CIK --> CIK column of my dataframe

df$year--> year column of my dataframe # (ranges from 1994-2015)

So ultimately I would want this

CIK1994 <- vector of unique CIKs in 1994 

CIK1995 <- vector of unique CIKs in 1995 

.....

CIK2015 <- vector of unique CIKs in 2015

Is there an efficient way I can create those vectors using a for-loop / lapply?

Jaap
  • 81,064
  • 34
  • 182
  • 193
jun.yoon77
  • 61
  • 1
  • 5
  • Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Sep 07 '16 at 20:10
  • At the very least, provide the output of `head(df)` – jakub Sep 07 '16 at 20:11

1 Answers1

0

Here's a loop:

set.seed(4444)
df <- round(data.frame(CIK=runif(50,10000,99999),year=runif(50,1994,2015)),0)

for(i in unique(df$year)) assign(paste0("CIK",i),unique(df$CIK[df$year==i]))
ddunn801
  • 1,900
  • 1
  • 15
  • 20