Say I had a dataframe:
get(data) #get() needs to be used here
And a list of its column names - or to be exact only one specific (there will always be only one):
> columnName
[1] "Type"
Next I need to refer to this column to change data type (and later I'll have to refer to the column many times, for plots and etc.):
> get(data)$columnName <- as.factor(get(data)$columnName)
Error in `$<-.data.frame`(`*tmp*`, columnName, value = integer(0)) :
replacement has 0 rows, data has 448
It means that I need to perform this in the end:
data$Type <- as.factor(data$Type)
I searched for this error but couldn't find anything that could resolve this. I'd be grateful if someone could help me resolve this.