1

Hi I have the below code for the purpose of adding a column called 'Area' with value 'Cambridge' for each row of a table. I'm then looking to select 3 columns and place the 'Area' column as the first column.

    TableOutput <- TableOutput %>%
+ add_column(Area = "Cambridge") %>%
+ select(Area, age, rollingRate) %>%
+ relocate(Area, .before = age)

I get the below error, can anyone advise please? Thank you.

Error in is.data.frame(.data) : argument ".data" is missing, with no default

camille
  • 16,432
  • 18
  • 38
  • 60
  • It's really hard to know without a [reproducible example](https://stackoverflow.com/q/5963269/5325862) or any idea of what these variables are or what you're looking at – camille Oct 19 '21 at 17:18
  • 1
    I removed the `+` at the beginning of each line because I often see people copy from the console and paste here, but if those were actually in your code I can roll back that edit – camille Oct 19 '21 at 17:21
  • 1
    @camille I think that is the error origin – akrun Oct 19 '21 at 17:21
  • 1
    Does this answer your question? [What does the "+" sign mean at the start of a line?](https://stackoverflow.com/questions/25636914/what-does-the-sign-mean-at-the-start-of-a-line) – camille Oct 19 '21 at 18:32

1 Answers1

2

It is just an issue with + sign which is probably copying the code directly from the console. The code should be without the +

iris %>%
 +  add_column(Area = "Cambridge")

Error in is.data.frame(.data) : argument ".data" is missing, with no default


Now, check with

iris %>%
    add_column(Area = "Cambridge")

-output

  Sepal.Length Sepal.Width Petal.Length Petal.Width    Species      Area
1            5.1         3.5          1.4         0.2     setosa Cambridge
2            4.9         3.0          1.4         0.2     setosa Cambridge
3            4.7         3.2          1.3         0.2     setosa Cambridge
4            4.6         3.1          1.5         0.2     setosa Cambridge
...
akrun
  • 874,273
  • 37
  • 540
  • 662