Hello,
i have a data frame with 2 columns and i want o add a third based on what is contained in my second column,
i have columns speed ( integer) , column measure ( in knots and km) I want to add a column that calculates the km per hr speed if colunm 2 is knots or returns the value in the speed colum which is already in km , i have tried the below for loop which returns with an error "number of items to replace is not a multiple of replacement lengthnumber"
my for loop is
selected_storms_2$KM_Wind_Speed <- c()
for (j in 1: length(selected_storms_2$measure))
{
if(selected_storms_2$measure[j] == 'knots' )
{selected_storms_2$KM_Wind_Speed[j] <- selected_storms_2$Speed *1.8 }
else if (selected_storms_2$measure[j] == 'km' )
{selected_storms_2$KM_Wind_Speed[j] <- selected_storms_2$Speed}
}
can anyone see what i am doing wrong ? is there another way ?
many thanks