Understanding the Data: how to combine two files with different number of columns?

I need to combine two data sets - training and test sets, which have a different number of columns (12 and 11, respectively).
But in version R v.3.6.4. as has showing on course “Big Mart Sales Prediction using R" for R v.3.4.0 (URL: https://courses.analyticsvidhya.com/courses/take/big-mart-sales-prediction-using-r/texts/6120085-understanding-the-data), following command:

test [, Item_Outlet_Sales: = NA]

leads to an error and the impossibility of further manipulation of the data.

Can someone tell me the working code for the version R v.3.6.4 working in RStudio?
Thank you very much in advance!

First: if you get error then show this error in question. Always show full error in questions.


I don’t uses R (but DataFrame in Python) and I don’t have access to this course but your example code looks like slicing data.

Using Google "R add column to dataframe" I found

R Data Frame: Create, Append, Select, Subset

and can confirm it.

For me works

 test$Item_Outlet_Sales <- NA

or

 test$Item_Outlet_Sales = NA

Tested with R 3.4.4 and 3.6.3 without R Studio (but it should works the same - IDE shouldn’t change R behavior)


> Some_Values <- c(1,2,3)
> test <- data.frame(Some_Values)

> test$Item_Outlet_Sales <- NA

> test

  Some_Values Item_Outlet_Sales
1           1                NA
2           2                NA
3           3                NA
© Copyright 2013-2019 Analytics Vidhya