Home > Net >  Add column to tibble in R - getting 'Error in is.data.frame(.data) : argument ".data"
Add column to tibble in R - getting 'Error in is.data.frame(.data) : argument ".data"

Time:10-20

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

CodePudding user response:

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
...
  •  Tags:  
  • r
  • Related