十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
R语言中,简单的S3和S4类的定义
10年的乌翠网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整乌翠建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“乌翠网站设计”,“乌翠网站推广”以来,每个客户项目都认真落实执行。
# S3 class
newstudent <- function(sid, sname, ssex){
tmp <- list(id = sid, name = sname, sex = ssex)
class(tmp) <- "student"
return(tmp)
}
print.student <- function(st){
cat(st$id, "\n")
cat(st$name, "\n")
cat(st$sex, "\n")
}
st = newstudent(11, "jack", "male")
#print(st)
st
# S4 class
setClass("student",
representation(
id = "numeric",
name = "character",
sex = "character"
))
# print is not a S4 generic. show methods are mapped to print for convenience, though.
setMethod("show", "student",
function(object){
cat(object@id, "\n")
cat(object@name, "\n")
cat(object@sex, "\n")
})
st = new("student", id = 41, name = "tom", sex = "male")
#print(st)
st