Hi,
I have a string vector imported from excel file as a single string "\r\n\r\nName\r\n\r\nPosition\r\n\r\nAge\r\n\r\nGender\r\n\r\nSam\r\n\r\nManager\r\n\r\n30\r\n\r\n Male\r\n\r\nMira\r\n\r\nHead\r\n\r\n25\r\n\r\nFemale\r\n\r\nMario\r\n\r\n40\r\n\r\nDirector\r\n\r\n Maria\r\n\r\n25\r\n\r\nOfficer\r\n\r\nFemale"
I am looking to convert this string to a data frame with column names are coming from first four values (Name, Position, Age, Gender). if there any missing cells to be Null or NA.
the table to be
Name |Position |Age |Gender
Sam |Manager |30 |Male
Mira |Head |25 |Female
Mario |Director |40 |NA
Maria |Officer |25 |Officer
I split the data into a vector with many rows,
bb <- c("\r\n\r\nName\r\n\r\nPosition\r\n\r\nAge\r\n\r\nGender\r\n\r\nSam\r\n\r\nManager\r\n\r\n30\r\n\r\n Male\r\n\r\nMira\r\n\r\nHead\r\n\r\n25\r\n\r\nFemale\r\n\r\nMario\r\n\r\n40\r\n\r\nDirector\r\n\r\n Maria\r\n\r\n25\r\n\r\nOfficer\r\n\r\nFemale")
bb_split <- bb %>% str_split(pattern ="\r\n\r\n") %>% unlist()
Then I tried many ways to add a column with a number and try to group rows with this number, but it turned into having a nest list without reaching to my gaol.
I appreciate your support.
Thanks.