خرید بک لینک

Vote count: 0

I'm creating an S3 constructor/object/script. I have a list in my script that needs to be printed like:

ID: 9876  Name: Virgil  Gender: M
LDL: 248* HDL: 45+  Triglycerides: 148

I defined a print function earlier.

print.ChlorReads <- function(theObject) {
  cat("ID: ", theObject$id, " Name: ", theObject$name, " Gender: ", theObject$gender,
      "n", "LDL: ", theObject$ldl, " HDL: ", theObject$hdl, " Triglycerides: ", theObject$trigl)
}

How do I properly use that script so that it prints each item in the list in the format specified above?

I can get it to print the list via print(lst), but, the list looks like this:

[[1]]
$id
[1] 1111

$name
[1] "Charlene"

$gender
[1] "F"

$ldl
[1] 111

$hdl
[1] 81

$trigl
[1] 136

attr(,"class")
[1] "Patient"

[[2]]
$id
[1] 2222

$name
[1] "Charles"

$gender
[1] "M"

$ldl
[1] 141

$hdl
[1] 78

$trigl
[1] 123

attr(,"class")
[1] "Patient"

[[3]]
$id
[1] 3333

$name
[1] "Kate"

$gender
[1] "F"

$ldl
[1] 121

$hdl
[1] 63

$trigl
[1] 141

attr(,"class")
[1] "Patient"

[[4]]
$id
[1] 4444

$name
[1] "Alice"

$gender
[1] "F"

$ldl
[1] 97

$hdl
[1] 79

$trigl
[1] 111

attr(,"class")
[1] "Patient"

[[5]]
$id
[1] 5555

$name
[1] "Jason"

$gender
[1] "M"

$ldl
[1] 121

$hdl
[1] 85

$trigl
[1] 123

attr(,"class")
[1] "Patient"

[[6]]
$id
[1] 6666

$name
[1] "Spencer"

$gender
[1] "M"

$ldl
[1] 111

$hdl
[1] 81

$trigl
[1] 127

attr(,"class")
[1] "Patient"

[[7]]
$id
[1] 7777

$name
[1] "Mary"

$gender
[1] "F"

$ldl
[1] 108

$hdl
[1] 86

$trigl
[1] 120

attr(,"class")
[1] "Patient"

[[8]]
$id
[1] 8888

$name
[1] "Jarrod"

$gender
[1] "M"

$ldl
[1] 252

$hdl
[1] 38

$trigl
[1] 411

attr(,"class")
[1] "Patient"

[[9]]
$id
[1] 9999

$name
[1] "Cary"

$gender
[1] "M"

$ldl
[1] 121

$hdl
[1] 47

$trigl
[1] 139

attr(,"class")
[1] "Patient"

[[10]]
$id
[1] 1234

$name
[1] "Michael"

$gender
[1] "M"

$ldl
[1] 123

$hdl
[1] 49

$trigl
[1] 134

attr(,"class")
[1] "Patient"

[[11]]
$id
[1] 2345

$name
[1] "Charlotte"

$gender
[1] "F"

$ldl
[1] 135

$hdl
[1] 69

$trigl
[1] 361

attr(,"class")
[1] "Patient"

[[12]]
$id
[1] 3456

$name
[1] "Blake"

$gender
[1] "F"

$ldl
[1] 95

$hdl
[1] 57

$trigl
[1] 126

attr(,"class")
[1] "Patient"

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 11 خرداد 1395 ساعت: 12:04

صفحه بندی