More specifically,  it shows the following when I typed traceback():

3: stop(sprintf(ngettext(N, "replacement has %d row, data has %d",
       "replacement has %d rows, data has %d"), N, nrows), domain = NA)
2: `$<-.data.frame`(`*tmp*`, "Z", value = numeric(0))
1: `$<-`(`*tmp*`, "Z", value = numeric(0))

I don't know what is the problem, as it works in the Console panel but not
in the top left panel. Thanks for your help.

On Sat, Mar 11, 2017 at 11:50 AM, lily li <chocol...@gmail.com> wrote:

> Hi R users,
>
> I have a problem about using R studio. For example, there is a dataframe
> that has many columns. I want to aggregated column X and column Y into
> column Z. Column Z does not exist before the aggregation. I use the code
> below:
> df$Z = df$X + df$Y
>
> However, it does not work in the top left panel in Rstudio, and has the
> following warning message:
> Error in `$<-.data.frame`(`*tmp*`, "Z", value = numeric(0)) :
>   replacement has 0 rows, data has 34333
>
> If I type the same code in the Console panel (bottom left panel), it
> works. How to deal with this problem? Thanks.
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to