我正在进行一项复杂的调查。我正在尝试使用svytable
来制作列联表。我使用了以下代码:
(tbl <- svytable(~sch.wide+stype, dclus1))
result
stype
sch.wide E H M
No 406.1640 101.5410 270.7760
Yes 4467.8035 372.3170 575.3989
我想要表中每个单元的百分比。类似于以下内容,
stype
sch.wide E H M
No 406.1640(xx%) 101.5410(xx%) 270.7760(xx%)
Yes 4467.8035(xx%) 372.3170(xx%) 575.3989(xx%)
感谢您的帮助
答案 0 :(得分:1)
一种简单的方法是使用#your input text
$string = "<P> Some text</P>";
#get the number of tab characters present in the string - note that this assumes they're all at the start
my @matches = $string =~ /\t/g;
#get the other parts of the string
$string =~ /(<P>)(\t+)(.*)(<\/P>)/g;
#add <BLOCKQUOTE> once for each match at the locations you've specified, and also cut out the existing tabs
$out = $1 . "<BLOCKQUOTE>" x @matches . $3 . "<BLOCKQUOTE>" x @matches . $4;
print "$out"
用原始值和比例替换表格对象的值:
paste0()