I have the number of rows in a list of type <
[1,] "Home"
[2,] "A"
[3,] "B"
[4,] "C"
[5,] "Home"
[6,] "D"
[7,] "E"
[8,] "Home"
[9,] "F"
[10,] "G"
[11,] "H"
[12,] "I"
these lines go dynamically ... after the "Home" there can be two, three, four, five or more subcategories .... so the binding does not work ... I have more than 5000 lines and the "Home" is usual at the beginning for each subcategory.
I want it to look like this.
[,1] [,2] [,3] [,4] [,5]
[1,] "Home" "A" "B" "C"
[2,] "Home" "D" "E"
[3,] "Home" "F" "G" "H" "I"
OR
I also used transpose to hide all rows in columns and when using transpose I got.
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
"Home" "A" "B" "C" "Home" "D" "E" "Home" "F" "G" "H" "I"
any solution will work for me either to convert rows to columns using the string match "Home"
or hidden columns to rows using a match for the string "Home" (transpose one) ....
Data
x <- c("Home", "A", "B", "C", "Home", "D", "E", "Home", "F", "G", "H", "I")
x <- matrix(x)
... ...
-... node
List <- c()
nodes <- html_nodes(file,".class a b c ") %>% html_text()
List[[length(List)+1]] = nodes
library(stringi)
catdf <- stri_list2matrix(List, byrow = TRUE)
catdf <- as.data.frame(catdf)