Set a single value in a data.table equal to NULL in R

r
data.table

#1

Hello,

I’ve been trying to delete a single value from a data.table but I am not able to do so. How to set a single value to NULL?

suppose my data.table is->

dt=data.table(1:3,c(“a”,“b”,“c”),3:1)
dt
V1 V2 V3
1: 1 a 3
2: 2 b 2
3: 3 c 1

and I want to delete b (2nd row and second column). How can I do it?
Thanks.


#2

Hello @Aditya_Sharma,

I am not sure if it can be set to NULL in R as in SQL but you can use:

dt=data.table(x=1:3,let=c("a","b","c"),y=3:1)
dt[2,2]<- NA

to set it to NA.