How to replace values (chosen by giving row and column) with NA

Hey guys, I have a 10 rows * 9 columns dataframe I am working with. However for the ninth row, I only want to keep the value in the first column and replace it with NA for the other 8 columns. Any ideas on how to do that? Btw the columns and rows have names at are not just numbers, but this shouldnt change anything right? Its just ["column name"] instead of [column number] for example.

I attached a picture of how my dataframe looks. Dont get confused that in the first Column its already NA. I also want to apply what i am asking for on other similar datasets where the value of firmSector in 1st column is not NA.

Thank you guys in advance

This can be done with mydf[9,2:9] <- NA. The subset indicates the columns 2 to 9 in the 9th row, which gets replaced using the assignment operator.

1 Like

This topic was automatically closed 42 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.