tab_split<-split(mydf,mydf$id)
unlist(lapply(tab_split,function(tab) cor(tab[,1],tab[,2])))
with the sample you gave:
mydf<-structure(list(s = c(1.6, 2.5, 4.8, 2.6, 3.5, 1.2, 2.5),
n = c(0.5,0.8, 0.7, 0.4, 0.66, 0.1, 0.45),
id = c(2L, 2L, 3L, 3L, 3L, 4L,4L)),
.Names = c("s", "n", "id"),
class = "data.frame",
row.names = c(NA, -7L))
> unlist(lapply(tab_split,function(tab) cor(tab[,1],tab[,2])))
2 3 4
1.000000 0.875128 1.000000
NB: if your column names are always "n" and "s", you can also do
unlist(lapply(tab_split,function(tab) cor(tab$s,tab$n)))