Displaying 1 result from an estimated 1 matches for "ninyear".
Did you mean:
newyear
2008 Oct 14
6
Doing a Task Without Using a For Loop
Assume that I have the dataframe "data1", which is listed at the end of this
message. I want count the number of lines that each person has for each
year. For example, the person with ID=213 has 15 entries (NinYear) for 1953.
The following bit of code calculates NinYear:
for (i in 1:length(data1$ID)) {
data1$NinYear[i] <- length(data1[data1$Year==data1$Year[i] &
data1$ID==data1$ID[i],1]) }
This seems to work but is horribly slow (some files I am working with have
over 500,000 lines). Can anyone...