I have recently started learning R and I am facing an issue. I have a column in my data which have height of players in (feet'inches) format. I want to create a new column for height in centimeters. For this I used the "strsplit" function as below(df is the height column):
l <- strsplit(df,"'",fixed = T)
print(l)
[[1]]
[1] "5" "7"
[[2]]
[1] "6" "2"
[[3]]
[1] "5" "9"
[[4]]
[1] "6" "4"
[[5]]
[1] "5" "11"
[[6]]
[1] "5" "8"
I am getting stuck here as I don't know how to obtain the required value after splitting the field.
I am trying to use the below code but its giving the following error:
p_pos <- grep("'",df)
l[[p_pos]][1]
Error in l[[p_pos]] : recursive indexing failed at level 2
I am expecting the above code to print the values from the first column in the list
5 6 5 6 5 5
>dput(head(df, 10))
c("5'7", "6'2", "5'9", "6'4", "5'11", "5'8")