NEW YORK (AP) _ A rerun of ''The Cosby Show'' knocked the series out of the top spot for only the fourth time this season, but NBC's ''Family Ties'' took over as No. 1 in the ratings from the A.C. Nielsen Co., and the network won the week.

CBS' four-part miniseries, ''I'll Take Manhattan,'' averaged a 22.9 rating and a 35 share, making it ''the first successful miniseries this season,'' according to CBS research analyst David Poltrack.

According to CBS, a miniseries is three parts or longer, and NBC's highly rated ''The Two Mrs. Grenvilles'' was a two-parter. According to CBS, the previous first-place finisher this season was the seven-part ''Amerika'' on ABC, which averaged a 19.0 rating and 29 share.

The rating is a percentage of the estimated 87.4 million households equipped with television. The share is a percentage of the available audience.

Despite preoccupation with 214 layoffs and a Writers Guild strike, CBS managed to stay on NBC's coattails in the news ratings. NBC averaged a rating of 11.6 and a 22 share; CBS had a 11.5 rating and 21 share; ABC had a ratinf of 10.1 and an 18 share.

The top 10 prime-time shows were: ''Family Ties,'' ''Cosby,'' ''Cheers,'' ''Night Court,'' ''Murder, She Wrote,'' ''Who's the Boss?'' ''Growing Pains,'' ''60 Minutes,'' ''Golden Girls'' and the movie ''The Karate Kid.''

NBC's ''ALF'' got its highest share of the audience ever, 27, and was ranked 20th. Alan Arkin's new series ''Harry'' had a so-so debut, getting a 16.0 rating and 24 share and landing in 30th out of the 64 shows rated.

CBS' new tongue-in-cheek ''Spies'' starring George Hamilton was in the dungeon, however, 63rd with a rating of 8.3.

NBC won the week with an average prime-time rating of 18.4. CBS was second with 17.2 and ABC was third with 13.3. The season-to-date average rating for NBC is 18.0. CBS is at 16.1 and ABC, 14.2.

A premiere of NBC's series, ''Rags to Riches,'' an ''Annie''-type story starring Joseph Bologna, got high numbers. According to overnight, tentative ratings from the 13 biggest cities, it won its time period with a 21.3 rating. Gerald Jaffe, NBC vice president for research projects, said the 21 weeks of the season that NBC has won out of the 24 so far equals the network's all-time high number of weekly wins from last year. One more win and the network will set a new all-time high.

''This will be our most successful season ever,'' Jaffe predicted.

CBS' showing of ''The Wizard of Oz'' was the lowest rating for the perennial children's favorite ever, but Poltrack said the movie is still doing better than the average television show after its 29th airing. Last year, it got an 18.4 rating and a 29 share.

The lowest-rated shows, from the bottom, were: ''Our World,'' ''Spies,'' ''Sledge Hammer 3/8'' ''Sidekicks,'' ''Wizard,'' ''Hotel,'' the TV movie ''Passions,'' ''Home,'' ''Outlaws'' and ''Ohara.''