问题描述
我有一个变量太多(+100)的数据。所以我想为每个变量创建一个交叉表。
那是我的代码:
Cell Contents
|-------------------------|
| N |
| N / Row Total |
|-------------------------|
Total Observations in Table: 226
| y
x | not bad | bad | Row Total |
-------------|-------------|-------------|-------------|
male | 79 | 48 | 127 |
| 0.622 | 0.378 | 0.562 |
-------------|-------------|-------------|-------------|
female | 72 | 27 | 99 |
| 0.727 | 0.273 | 0.438 |
-------------|-------------|-------------|-------------|
Column Total | 151 | 75 | 226 |
-------------|-------------|-------------|-------------|
...
这就是我的输出:
| y
x | not bad | bad | Row Total |
class MainActivity : AppCompatActivity() {
private var posiljkaDAO: PosiljkaDAO? = null
private var dostavnaKnjizicaDAO: DostavnaKnjizicaDAO? = null
private var allItems: ArrayList<DostavnaKnjizicaModel> = arrayListOf()
var adapter = RecycleViewAdapter(allItems)
private var eSifraPosiljke: EditText? = null
@RequiresApi(Build.VERSION_CODES.O)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_listview)
//get logo
supportActionBar!!.setDisplayShowHomeEnabled(true)
supportActionBar!!.setLogo(R.drawable.logo_bp)
supportActionBar!!.setDisplayUseLogoEnabled(true)
dostavnaKnjizicaDAO = DostavnaKnjizicaDAO(this)
dostavnaKnjizicaDAO?.closeDB()
getAllItems(this)
//connecting adapter and recyclerView
adapter = RecycleViewAdapter(allItems)
recycleView.adapter = adapter
recycleView.layoutManager = LinearLayoutManager(this)
recycleView.setHasFixedSize(true)
eSifraPosiljke = findViewById<EditText>(R.id.eSifraPosiljke)
posiljkaDAO = PosiljkaDAO(this)
}
//method that gets all items from database
private fun getAllItems(context: Context) {
var dostavenFromLOcal = dostavnaKnjizicaDAO?.getAllLocalDostavneKnjizice(context)
if (dostavenFromLOcal != null) {
allItems = dostavenFromLOcal
}
}
//method that changes status of an item
fun changeStatus(context: Context,IdDostavne: Int,statusDostavne: Int) {
dostavnaKnjizicaDAO = DostavnaKnjizicaDAO(context)
dostavnaKnjizicaDAO?.changeStatus(IdDostavne,statusDostavne)
getAllItems(context)
adapter.notifyDataSetChanged()
}
}
我想用每个不同的姓氏来更改x和y,但我一直无法弄清。
感谢您的帮助。
解决方法
也许有人需要。
我正在像这样在函数源代码中更改rowName和ColName
CrossTable2<-function (x,y,digits = 3,max.width = 5,expected = FALSE,prop.r = TRUE,prop.c = TRUE,prop.t = TRUE,prop.chisq = TRUE,chisq = FALSE,fisher = FALSE,mcnemar = FALSE,resid = FALSE,sresid = FALSE,asresid = FALSE,missing.include = FALSE,format = c("SAS","SPSS"),dnn = NULL,coldata,rowdata,...)
{
format = match.arg(format)
RowData <- toString(rowdata)
if (!missing(y))
ColData <- deparse(coldata)