In Order to get sign of a column we will be using using sign() function. Let’s see how to extract the sign of a column in R with an example.
Let’s first create the dataframe.
### Create Data Frame df1 = data.frame (state =c('Arizona','California','Texas','Las Vegas','Indiana','Alaska','unknown'),Hindex =c(62,-47,55,-74,31,-77,0)) df1
So the resultant dataframe will be
Get sign of a column in R:
Sign function is used to extract the sign of a column. As shown below
# Get sign of a column df1$sign_hindex <- sign (df1$Hindex) df1
so the resultant sign value is stored in another column named “sign_hindex”. So the resultant dataframe will be