I’m relatively new R user and still learning the basics.
I have a named list xx those entries looks like this:
> xx[100:105]
$`15LOX-1`
[1] "207328_at"
$`16.1`
[1] "215946_x_at"
$`16.2`
[1] NA
$`16.3A5`
[1] "200983_x_at" "200984_s_at" "200985_s_at" "212463_at" "228748_at"
$`160-KD`
[1] "201224_s_at" "201225_s_at"
$`1600019D15Rik`
[1] "218465_at" "222642_s_at" "225492_at" "235907_at" "238831_at"
I would like to save it to a text file with two columns – Key and Value. If several strings correspond to the same key they should be in different rows. Double-quote symbols are not required.
In addition, how I can avoid NA values to be saved?
Please help.
Recreate test data:
First, remove all the NA values:
Now, create a temporary variable that stores the length of each element in x:
Now use
repto create the key (i.e. repeat the names of x, each time the length of the associated element), and use a combination ofunlistandunnameto create the values:This produces:
Finally, use
write.csv(x, file=...)or your favourite write function to save the data to file.