I want to remove the NA's from this data.frame, so that I have two columns with 24 rows in each column. Any ideas? The data frame is named AtmWtAg.long.to.wide. Not sure which command to use. !is.na omit.na
AtmWtAg.long.to.wide
1 2
1 107.8681568 NA
2 107.8681465 NA
3 107.8681572 NA
4 107.8681785 NA
5 107.8681446 NA
6 107.8681903 NA
7 107.8681526 NA
8 107.8681494 NA
9 107.8681616 NA
10 107.8681587 NA
11 107.8681519 NA
12 107.8681486 NA
13 107.8681419 NA
14 107.8681569 NA
15 107.8681508 NA
16 107.8681672 NA
17 107.8681385 NA
18 107.8681518 NA
19 107.8681662 NA
20 107.8681424 NA
21 107.8681360 NA
22 107.8681333 NA
23 107.8681610 NA
24 107.8681477 NA
25 NA 107.8681079
26 NA 107.8681344
27 NA 107.8681513
28 NA 107.8681197
29 NA 107.8681604
30 NA 107.8681385
31 NA 107.8681642
32 NA 107.8681365
33 NA 107.8681151
34 NA 107.8681082
35 NA 107.8681517
36 NA 107.8681448
37 NA 107.8681198
38 NA 107.8681482
39 NA 107.8681334
40 NA 107.8681609
41 NA 107.8681101
42 NA 107.8681512
43 NA 107.8681469
44 NA 107.8681360
45 NA 107.8681254
46 NA 107.8681261
47 NA 107.8681450
48 NA 107.8681368
Asked
Active
Viewed 45 times
0

Marvin Bahr
- 135
- 1
- 2
- 11
-
[X-Y problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) I reckon. I'm guessing you shouldn't have got this output in the first place. Show the code that made this "wide" dataset, and I reckon a simple change will fix it. – thelatemail Jun 21 '17 at 02:46
-
My question isn't a duplicate because I don't want to remove the rows with NA's in just the NA's. I have to use the reshape command to go from long to wide. In the wide format there should just be two columns with no NA's listed with length 24 rows as mentioned. – Marvin Bahr Jun 21 '17 at 03:35
-
Probably not a duplicate, and `dat[] <- lapply(dat, na.omit)` may do what you want. My point however was that the dataset you show looks to have been reshaped incorrectly. If you go back one step to whatever created this dataset, you can probably solve your problem before it occurs. Is this the original data: http://www.itl.nist.gov/div898/strd/anova/AtmWtAg.dat ? – thelatemail Jun 21 '17 at 03:39
-
For instance, using the `AtmWtAg` data from the link you could do `reshape(transform(AtmWtAg,id=ave(Instrument,Instrument,FUN=seq_along)), idvar="id", timevar="Instrument", direction="wide")` as a general solution or even just `unstack(AtmWtAg[2:1])` to reshape properly. – thelatemail Jun 21 '17 at 03:48
-
I have to use the reshape function, but here is what I have: AtmWtAg.long.to.wide <- reshape(AtmWtAg.long1, v.names="AgWt", varying=list(names(AtmWtAg.wide)), idvar= "ID", ids=c("1", "2"), timevar="Instrument", direction="wide") ID <- 1:nrow(AtmWtAg.long) AtmWtAg.long1 <- cbind(AtmWtAg.long,ID) – Marvin Bahr Jun 21 '17 at 12:40