R how to extract specific elements in a data frame consisting of character lists -


i have data frame labels consisting of 3 rows of 1 column this:

 labels                   labels(n)  1 text, commission20120125  2    text, council2015mmdd  3 text, parliament20140312 

with:

 labels[1,]  [[1]]  [1] "text"               "commission20120125" 

and:

  labels[2,]   [[1]]  [1] "text"            "council2015mmdd" 

and:

 labels[3,]  [[1]]  [1] "text"               "parliament20140312" 

is there "simple" way access "text" , put in vector, this:

c("commission20120125", "council2015mmdd", "parliament20140312") 

as solution far manually do:

l1 <- as.vector(labels[1,])   l1 <- unlist(l1)   l1 <- str_extract(l1, "[a-z][a-z]+[0-9]+") l <- l1[2] 

and on every raw.

you may try

sapply(labels[,1], '[',2) #[1] "commission20120125" "council2015mmdd"    "parliament20140312" 

data

labels <- data.frame(labelsn = i(list(c('text', 'commission20120125'),  c('text', 'council2015mmdd'), c('text', 'parliament20140312')))) 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -