The R language is a robust data analysis language, so when there is an error with the code, many times the error message returned is quite generic and technical. There are some error messages that do pop up fairly frequently though, and this article lists some of those and what types of issues they indicate. If you check Properties > OUTPUT > Show raw R Output your output will show each line of code ran and the error message beside the line of code that is causing the error. Then you can look into the errors below or see How to Troubleshoot R Code.
Incorrect number of dimensions / subscript out of bounds
The below code will produce an incorrect number of dimensions error due to the last line:
x = table.Gender
#return Female value
If we add
dim(x) to the code, we will see that it returns only a 3, that is 3 rows. There is not a second value because there is no additional column dimension. The solution therefore is to change the last line to
Not equal to array extent / number of items to replace is not a multiple of replacement length
The below code will produce a length of 'dimnames'  not equal to array extent error due to the last line:
x = table.Living.arrangements
#new row names
newrows = c("Parents","Alone","Partner","Children","Partner + Children","Sharing","Other")
rownames(x) = newrows
If we add
length(newrows) to the code, we will see that one returns 8 and the other 7. We can only replace the row names with the exact same number of items. The solution is to either add "NET" to the end of the newrows object or remove it from the source table via right-click > Hide.
Missing / duplicated rows or columns
The below code attempts to merge these two tables together but doesn't return the correct result:
x = table.Preferred.cola.2
y = table.Q4.Brand.Attitude.T2B
If we add
head(y), we can view the figures as they should align. However, this doesn't solve the immediate problem. We can also compare the row names by using the below to see what labels don't match:
What we can see here is that the Pepsi label has a trailing space in one table which causes the merged table not to align properly. The solution is to right-click > Rename this label in the preference table and remove the space.