0 votes
1 view
in R Programming by (44.6k points)

I am having the following dataframe:

Col1 Col2

A 23

B NA

C 21

D 2

E NA

F 9

and I just want to add add a new Col3 with presence/absence info (1/0). Let say for instance if the number in col2 >=1, then I will put 1 in Col3 and if it is NA then I will put 0.

Col1 Col2 Col3

A    23 1

B    NA 0

C    21 1

D    2 1

E    NA 0

F    9 1

1 Answer

0 votes
by (96.7k points)

With the help of R programming, you can simply add the another column with the help of the following syntax:

df$col3 <- +(df$Col2 >= 1 & !is.na(df$Col2)) 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...