Mean Imputation
Kingsley Labs runs an assay that occasionally fails to read a well, and the plate reader writes NA on those lines. The analysis downstream cannot cope with gaps at all, so every gap is filled beforehand with the mean of the wells that did read — a stand-in chosen precisely because it leaves the column's own average where it was. The filled column must come back the same length and in the same order, since each line corresponds to a physical well on the plate.
Task: Print the column with every gap filled by the mean of the readings that are present.
Input
The first line holds one integer n, how many lines follow. Each of the next n lines holds either a reading as a plain number or the exact text NA for a well that failed. At least one line is a real reading.
Output
n lines, in the same order as the input. Each line holds either that well's original reading or, where the well failed, the fill value — every line with exactly one digit after the decimal point.
Example:
Input:
5
10
NA
20
NA
30
Output:
10.0
20.0
20.0
20.0
30.0
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in