Error: missing values are not allowed in subscripted assignments of dataframes

When I try to run the following code:

Full_df[!is.na(match(Subset_df$cell_name,Empty_df$cell_name)),]$Freq <- Subset_df$Freq

I get the following error: Error in [<-.data.frame ( *tmp* , match(Subset_df$cell_name, Empty_df$cell_name), : missing values are not allowed in subscripted assignments of data frames

I have seen other forum questions in which they use !is.na or subset(), but as I'm not an expert in R, I don't know to place this in the code and get it to run.

Could you talk more about what you're trying to do here? Ideally with a reprex?

There's a nice discussion of this error on stack overflow, and in the documentation for R data.frames:

The replacement methods can be used to add whole column(s) by specifying non-existent column(s), in which case the column(s) are added at the right-hand edge of the data frame and numerical indices must be contiguous to existing indices. On the other hand, rows can be added at any row after the current last row, and the columns will be in-filled with missing values. Missing values in the indices are not allowed for replacement.

This likely means there's a missing value in your Freq column of Full_df.

Here's a reprex for this error.

x <- data.frame(a=c(NA,2:5), b=c(1:5))
x[x$a==2,]$b
#> [1] NA  2
x[x$a==2,]$b <- 99
Error in `[<-.data.frame`(`*tmp*`, x$a == 2, , value = list(a = c(NA,  : 
  missing values are not allowed in subscripted assignments of data frames

Created on 2021-04-13 by the reprex package (v2.0.0)


I think a good path forward is to start your goal for this operation, what are you trying to do? With a reprex, folk here could probably suggest an alternative.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.