1

I have a table with two columns A,B and a lot of rows. Each value like a1 in A has a relation with some values like b1,b2,...,bk in B. In other words, my table is:

A   B
a1  b1
a1  b2
.
.
.
a1  bk
a2  b'1
a2  b'2
.
.
.
a2  b'k'
.
.
.

I was wondering how to convert this table to a list or vector in R. I converted my table to a file and used read.table function. Here is my code:

df <- read.table("MyData.csv", header = TRUE)
lapply(unique(df$A), function(x){
  paste0( x, ' = ', '(', paste( df[ df$A == x, ]$B, collapse = ","), ')' )
})

But the result of lapply has not any value. In fact, I want to show this table for each value in A in this format:

a1 = (b1, b2, ..., bk)
a2 = (b'1,b'2, ..., b'k')
.
.
.
Patris
  • 167
  • 2
  • 11

0 Answers0