Skip to content
Prev 301156 / 398503 Next

reshaping data

Hello,

Try the following.


# We are going to use this twice
sl <- split(long, long$id)

# Remove groups with only one row
l2 <- lapply(sl, function(x) if(nrow(x) > 1) x)
l2 <- do.call(rbind, l2)
l2

# Create a new variable
l3 <- lapply(sl, function(x) cbind(x, NEW_VARIABLE=seq_len(nrow(x))))
l3 <- do.call(rbind, l3)
l3


Hope this helps,

Rui Barradas

Em 25-07-2012 01:59, AC Del Re escreveu: