Skip to content
Prev 298831 / 398503 Next

Insert row in specific location between data frames

Hello,

When I've asked you to dput() your datasets, I meant all of the output 
of dput(), for us to copy it and paste in an R session. It is the 
easiest way of recreating exact copies of the objects.

Like this, with those "................" it's unusable.

Now, as far as I can see, you have a data.frame called groupA with 25 
rows and a vector of 24 elements. after including an NA in 11th position 
the vector length becomes 25. This part was already answered to.

Then you want to put that vector as a column of groupA. You do NOT need 
'with', this will do:

groupA$predict_SO2 <- predict_SO2_a


Then you want to merge this resulting data.frame with another 
data.frame, groupB, right? But merge returns a data.frame with 0 rows.

What went wrong? The common columns combined don't have the same values.

Why not? Because column 'Date' is a factor, not a date. The labels, 
i.e., the dates values, might be equal but the factors, how they are 
coded, are not.

Use the following.


x <- with(groupA, levels(Date)[Date])
x <- as.Date(x, format="%d/%m/%Y")
groupA$Date <- x

And the same for groupB. Only then try to merge them.

And next time paste the output of dput(), ALL of it.

Hope this helps,

Rui Barradas

Em 02-07-2012 05:39, pigpigmeow escreveu: