PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, August 13, 2022

[FIXED] How to make a output result as a table form in R

 August 13, 2022     dataframe, datatable, output, r     No comments   

Issue

I am having the three output results as below,

structure(c("[1] \"lls_loess\" \"lls_rlr\"   \"knn_loess\"", 
"[1] \"lls_loess\" \"lls_rlr\"   \"knn_loess\"", "[1] \"lls_loess\" \"lls_rlr\"   \"lls_vsn\"  "
), dim = c(1L, 3L), dimnames = list(NULL, c("Based_on_PCV", "Based_on_PEV", 
"Based_on_PMAD")))

I have used the names() code for extracting the names from the result output.

And I want to give the output to the user in the format as in the picture. example result format

Please suggest some R code for this matter.


Solution

Well... this is some quite ugly data, one possible solution

x=structure(c("[1] \"lls_loess\" \"lls_rlr\"   \"knn_loess\"", 
            "[1] \"lls_loess\" \"lls_rlr\"   \"knn_loess\"", "[1] \"lls_loess\" \"lls_rlr\"   \"lls_vsn\"  "
), dim = c(1L, 3L), dimnames = list(NULL, c("Based_on_PCV", "Based_on_PEV", 
                                            "Based_on_PMAD")))
df=data.frame(x)

data.frame(
  sapply(
    sapply(
      df,
      function(i){
        strsplit(
          gsub('"',",",gsub('\\[[0-9]+\\]| ',"",i)),
          ","
        )
      }
    ),
    function(j){j[j!=""]}
  )
)

  Based_on_PCV Based_on_PEV Based_on_PMAD
1    lls_loess    lls_loess     lls_loess
2      lls_rlr      lls_rlr       lls_rlr
3    knn_loess    knn_loess       lls_vsn


Answered By - user2974951
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing