I have a simple frame as such:
ID Col1 Col2 Col3 Col4 1 NA NA NA NA 1 5 10 NA NA 1 NA NA 15 20 2 NA NA NA NA 2 25 30 NA NA 2 NA NA 35 40
And I would like to reformat it as such:
ID Col1 Col2 Col3 Col4 1 5 10 15 20 2 25 30 35 40
(note: the real data set contains thousands of rows, and the values ββare from biological data; NA does not follow a simple pattern, except that NA do not intersect, and yes there are exactly 3 rows for each ID ).
STEP ONE : Get rid of strings that have only NA values.
At first glance, it looked simple, but I ran into some problems.
complete.cases(DF) returns all FALSE , so I cannot use this to delete rows with all NA s, as in DF[complete.cases(DF),] . This is because all lines contain at least one NA .
Since is.na want to multiply, other schemes using is.na come out for the same reason.
STEP TWO strong>: Collapse the remaining two lines into one.
Thinking of using something like aggregate to do this, but there is an easier way than this that doesn't work at all.
Thanks for any advice.
r aggregate na
Matt O'Brien
source share