[R] About error in the panel
William Dunlap
wdunlap at tibco.com
Sat Mar 11 23:25:33 CET 2017
You will get this error if 'df' does not have columns named "X" and
"Y", so df$X or df$Y is NULL. E.g.,
> df <- data.frame(One=1:3, Two=11:13)
> df$Three <- df$One + df$noSuchColumn
Error in `$<-.data.frame`(`*tmp*`, "Three", value = numeric(0)) :
replacement has 0 rows, data has 3
What does names(df) show in the different panels?
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Sat, Mar 11, 2017 at 10:50 AM, lily li <chocold12 at 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 at 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.
More information about the R-help
mailing list