Home > Mobile >  How do I export a dataframe produced by R?
How do I export a dataframe produced by R?

Time:04-15

I fail to export a dataframe produced by uco(seqinr) function in rscu computation. What means should I use?. The dataframe is not showing in r environment either, it only remain in the console. Have tried so much copying it to excel, word, notepad in vain. Could someone help?

> library("seqinr")
> rcds <- read.fasta("virus.fasta")[[1]]
> uco( rcds, index = "freq")

        aaa         aac         aag         aat         aca         acc 
0.068669528 0.025751073 0.004291845 0.030042918 0.030042918 0.012875536 
        acg         act         aga         agc         agg         agt 
0.008583691 0.012875536 0.034334764 0.000000000 0.008583691 0.025751073 
        ata         atc         atg         att         caa         cac 
0.025751073 0.012875536 0.017167382 0.034334764 0.017167382 0.008583691 
        cag         cat         cca         ccc         ccg         cct 
0.008583691 0.004291845 0.017167382 0.004291845 0.004291845 0.008583691 
        cga         cgc         cgg         cgt         cta         ctc 
0.008583691 0.000000000 0.000000000 0.004291845 0.004291845 0.012875536 
        ctg         ctt         gaa         gac         gag         gat 
0.012875536 0.008583691 0.008583691 0.004291845 0.021459227 0.012875536 
        gca         gcc         gcg         gct         gga         ggc 
0.021459227 0.004291845 0.000000000 0.008583691 0.017167382 0.000000000 
        ggg         ggt         gta         gtc         gtg         gtt 
0.004291845 0.012875536 0.008583691 0.000000000 0.008583691 0.012875536 
        taa         tac         tag         tat         tca         tcc 
0.047210300 0.017167382 0.034334764 0.047210300 0.008583691 0.017167382 
        tcg         tct         tga         tgc         tgg         tgt 
0.004291845 0.004291845 0.034334764 0.017167382 0.025751073 0.012875536 
        tta         ttc         ttg         ttt 
0.017167382 0.017167382 0.034334764 0.038626609 
> uco( rcds, index = "eff")

aaa aac aag aat aca acc acg act aga agc agg agt ata atc atg att caa cac 
 16   6   1   7   7   3   2   3   8   0   2   6   6   3   4   8   4   2 
cag cat cca ccc ccg cct cga cgc cgg cgt cta ctc ctg ctt gaa gac gag gat 
  2   1   4   1   1   2   2   0   0   1   1   3   3   2   2   1   5   3 
gca gcc gcg gct gga ggc ggg ggt gta gtc gtg gtt taa tac tag tat tca tcc 
  5   1   0   2   4   0   1   3   2   0   2   3  11   4   8  11   2   4 
tcg tct tga tgc tgg tgt tta ttc ttg ttt 
  1   1   8   4   6   3   4   4   8   9 
> uco( rcds, index = "rscu")
      aaa       aac       aag       aat       aca       acc       acg 
1.8823529 0.9230769 0.1176471 1.0769231 1.8666667 0.8000000 0.5333333 
      act       aga       agc       agg       agt       ata       atc 
0.8000000 3.6923077 0.0000000 0.9230769 2.5714286 1.0588235 0.5294118 
      atg       att       caa       cac       cag       cat       cca 
1.0000000 1.4117647 1.3333333 1.3333333 0.6666667 0.6666667 2.0000000 
      ccc       ccg       cct       cga       cgc       cgg       cgt 
0.5000000 0.5000000 1.0000000 0.9230769 0.0000000 0.0000000 0.4615385 
      cta       ctc       ctg       ctt       gaa       gac       gag 
0.2857143 0.8571429 0.8571429 0.5714286 0.5714286 0.5000000 1.4285714 
      gat       gca       gcc       gcg       gct       gga       ggc 
1.5000000 2.5000000 0.5000000 0.0000000 1.0000000 2.0000000 0.0000000 
      ggg       ggt       gta       gtc       gtg       gtt       taa 
0.5000000 1.5000000 1.1428571 0.0000000 1.1428571 1.7142857 1.2222222 
      tac       tag       tat       tca       tcc       tcg       tct 
0.5333333 0.8888889 1.4666667 0.8571429 1.7142857 0.4285714 0.4285714 
      tga       tgc       tgg       tgt       tta       ttc       ttg 
0.8888889 1.1428571 1.0000000 0.8571429 1.1428571 0.6153846 2.2857143 
      ttt 
1.3846154 
> uco( rcds, as.data.frame = FALSE, NA.rscu = NA)

aaa aac aag aat aca acc acg act aga agc agg agt ata atc atg att caa cac 
 16   6   1   7   7   3   2   3   8   0   2   6   6   3   4   8   4   2 
cag cat cca ccc ccg cct cga cgc cgg cgt cta ctc ctg ctt gaa gac gag gat 
  2   1   4   1   1   2   2   0   0   1   1   3   3   2   2   1   5   3 
gca gcc gcg gct gga ggc ggg ggt gta gtc gtg gtt taa tac tag tat tca tcc 
  5   1   0   2   4   0   1   3   2   0   2   3  11   4   8  11   2   4 
tcg tct tga tgc tgg tgt tta ttc ttg ttt 
  1   1   8   4   6   3   4   4   8   9 
> uco( rcds, as.data.frame = TRUE, NA.rscu = NA)
     AA codon eff        freq      RSCU
aaa Lys   aaa  16 0.068669528 1.8823529
aac Asn   aac   6 0.025751073 0.9230769
aag Lys   aag   1 0.004291845 0.1176471
aat Asn   aat   7 0.030042918 1.0769231
aca Thr   aca   7 0.030042918 1.8666667
acc Thr   acc   3 0.012875536 0.8000000
acg Thr   acg   2 0.008583691 0.5333333
act Thr   act   3 0.012875536 0.8000000
aga Arg   aga   8 0.034334764 3.6923077
agc Ser   agc   0 0.000000000 0.0000000
agg Arg   agg   2 0.008583691 0.9230769
agt Ser   agt   6 0.025751073 2.5714286
ata Ile   ata   6 0.025751073 1.0588235
atc Ile   atc   3 0.012875536 0.5294118
atg Met   atg   4 0.017167382 1.0000000
att Ile   att   8 0.034334764 1.4117647
caa Gln   caa   4 0.017167382 1.3333333
cac His   cac   2 0.008583691 1.3333333
cag Gln   cag   2 0.008583691 0.6666667
cat His   cat   1 0.004291845 0.6666667
cca Pro   cca   4 0.017167382 2.0000000
ccc Pro   ccc   1 0.004291845 0.5000000
ccg Pro   ccg   1 0.004291845 0.5000000
cct Pro   cct   2 0.008583691 1.0000000
cga Arg   cga   2 0.008583691 0.9230769
cgc Arg   cgc   0 0.000000000 0.0000000
cgg Arg   cgg   0 0.000000000 0.0000000
cgt Arg   cgt   1 0.004291845 0.4615385
cta Leu   cta   1 0.004291845 0.2857143
ctc Leu   ctc   3 0.012875536 0.8571429
ctg Leu   ctg   3 0.012875536 0.8571429
ctt Leu   ctt   2 0.008583691 0.5714286
gaa Glu   gaa   2 0.008583691 0.5714286
gac Asp   gac   1 0.004291845 0.5000000
gag Glu   gag   5 0.021459227 1.4285714
gat Asp   gat   3 0.012875536 1.5000000
gca Ala   gca   5 0.021459227 2.5000000
gcc Ala   gcc   1 0.004291845 0.5000000
gcg Ala   gcg   0 0.000000000 0.0000000
gct Ala   gct   2 0.008583691 1.0000000
gga Gly   gga   4 0.017167382 2.0000000
ggc Gly   ggc   0 0.000000000 0.0000000
ggg Gly   ggg   1 0.004291845 0.5000000
ggt Gly   ggt   3 0.012875536 1.5000000
gta Val   gta   2 0.008583691 1.1428571
gtc Val   gtc   0 0.000000000 0.0000000
gtg Val   gtg   2 0.008583691 1.1428571
gtt Val   gtt   3 0.012875536 1.7142857
taa Stp   taa  11 0.047210300 1.2222222
tac Tyr   tac   4 0.017167382 0.5333333
tag Stp   tag   8 0.034334764 0.8888889
tat Tyr   tat  11 0.047210300 1.4666667
tca Ser   tca   2 0.008583691 0.8571429
tcc Ser   tcc   4 0.017167382 1.7142857
tcg Ser   tcg   1 0.004291845 0.4285714
tct Ser   tct   1 0.004291845 0.4285714
tga Stp   tga   8 0.034334764 0.8888889
tgc Cys   tgc   4 0.017167382 1.1428571
tgg Trp   tgg   6 0.025751073 1.0000000
tgt Cys   tgt   3 0.012875536 0.8571429
tta Leu   tta   4 0.017167382 1.1428571
ttc Phe   ttc   4 0.017167382 0.6153846
ttg Leu   ttg   8 0.034334764 2.2857143
ttt Phe   ttt   9 0.038626609 1.3846154
>

This is the output from the computation

CodePudding user response:

First of all, store the output of the function in a variable, e.g.:

results_final_v2 <- uco( rcds, index = "freq")

For the names of your variables, you can use any letters A-Z, a-z, 0-9, underscore. Best avoid special characters.

Now you will see the results in the R environment, and other functions will be able to use it. It won't show in the console automatically, but you can still view it by just typing the name of your variable, e.g. results_final_v2.

Now to export your data. To export it to other R users:

save(results_final_v2, file='export1.RData')

You can specify multiple variable names, if you want to export multiple variables into one file.

To export to CSV (for Excel):

write.csv(results_final_v2, file='export1.csv'

In Excel, you import the resulting .csv file through 'Import' or 'Data > From Text'. For European users, write.csv2() usually works better.

There are also methods to write to an xlsx file directly or copy the data to the clipboard.

  • Related