> X <- sample(c("Smith", "", "Johnson"), 80, replace=TRUE)
> X
[1] "Johnson" "" "" "Johnson" "Smith"
[6] "" "" "Smith" "Johnson" "Johnson"
[11] "" "" "Smith" "Smith" "Johnson"
[16] "Johnson" "" "" "Smith" "Johnson"
[21] "Smith" "Johnson" "Smith" "" "Smith"
[26] "Smith" "" "Smith" "Johnson" ""
[31] "" "Smith" "" "" "Johnson"
[36] "Smith" "Smith" "" "Johnson" ""
[41] "Smith" "Smith" "Smith" "Johnson" ""
[46] "" "" "" "" "Johnson"
[51] "" "" "" "Johnson" "Johnson"
[56] "Johnson" "" "Johnson" "Johnson" "Smith"
[61] "" "" "" "Johnson" "Johnson"
[66] "" "" "Smith" "Smith" "Johnson"
[71] "" "Johnson" "" "Johnson" "Johnson"
[76] "Smith" "Smith" "Johnson" "Smith" "Smith"
> for(i in seq(along=X)[-1]){X[i] <- if(X[i] == "" | is.na(X[i])) X[i -
1] else X[i]}
> X
[1] "Johnson" "Johnson" "Johnson" "Johnson" "Smith"
[6] "Smith" "Smith" "Smith" "Johnson" "Johnson"
[11] "Johnson" "Johnson" "Smith" "Smith" "Johnson"
[16] "Johnson" "Johnson" "Johnson" "Smith" "Johnson"
[21] "Smith" "Johnson" "Smith" "Smith" "Smith"
[26] "Smith" "Smith" "Smith" "Johnson" "Johnson"
[31] "Johnson" "Smith" "Smith" "Smith" "Johnson"
[36] "Smith" "Smith" "Smith" "Johnson" "Johnson"
[41] "Smith" "Smith" "Smith" "Johnson" "Johnson"
[46] "Johnson" "Johnson" "Johnson" "Johnson" "Johnson"
[51] "Johnson" "Johnson" "Johnson" "Johnson" "Johnson"
[56] "Johnson" "Johnson" "Johnson" "Johnson" "Smith"
[61] "Smith" "Smith" "Smith" "Johnson" "Johnson"
[66] "Johnson" "Johnson" "Smith" "Smith" "Johnson"
[71] "Johnson" "Johnson" "Johnson" "Johnson" "Johnson"
[76] "Smith" "Smith" "Johnson" "Smith" "Smith"
CHUL LEE wrote:
Dear list,
It is not an issue of S-Plus, but I know someone in this forum can
help me.
I have data which have missing cases. I want to replace this missing
with above value. For example,
Col1 Col2
Smith 3
2.5
4
Johnson 4
4.5
3
2.5
In this case, I want to replace Row 2 & 3 in Col1 with Smith, but Row
5,6,&7 with Johnson. Is there a easy way to do by Excel or with
Statistics programs? This data has more than 80,000 rows.
Chul
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894
|