in Qt u can get data from index like this 'Index.data().toString()', i need opposite. I have data and i want index.
Is there in Qt some native function? Or i have to map those data in some array for example
In order to obtain the index by data, you have to traverse your table to find corresponding row and column numbers. You can do it manually, or using QAbstractItemModel::match() function. For example:
QModelIndexList foundIndexes = tableView->model()->match(QModelIndex(),
Qt::DisplayRole,
"My String");
You can change the function arguments to get search result that better fits your need.
Related
I am looking to optimize my contains query. I have a pipe separated list of numbers in one of my Aerospike bins(columns) something like 234|235|236|
These numbers may vary from 1 to 2^14
Currently I am applying a contains query to find 235| in this column but it is getting slow. Is there any Math or any strategy I can apply to convert this contains query to an exact match??
TIA,
Karan
Did you try using a List type for this bin? You can then build a secondary index on the List values (indextype = LIST, type=NUMERIC)and get all records that match the value of interest in the list using a secondary index query.
I have a SpatialLinesDataFrame named df with a number of attributes. These attributes represent the permutations of three dimensions:
dim1
dim2
dim3
The attributes thus are:
df$dim1a.dim2a.dim3a
df$dim1a.dim2a.dim3b
df$dim1a.dim2b.dim3a
...
df$dim1b.dim2a.dim3a
df$dim1b.dim2a.dim3b
...
df$dim1n.dim2n.dim3n
I am now trying to make my data accessible in Shiny, where I offer a widget item for each dimensions that allows the user select one value for that dimension. If the user selects
dim1a
dim2c
dim3b
I want to display data for df$dim1a.dim2c.dim3b.
How can I dynamically access the part of the data frame that the user is asking to have displayed?
I can construct the name of the attribute by constructing it via
display_data <- paste0(input$radioButton_dim1,'.',input$radioButton_dim2,'.',input$radioButton_dim3)
But how can I refer to it when trying to select it from the df or subset the data frame to select the data?
+++ Update:
When I try subsetting the data frame by using df[,display_data], the objects of class "Lines" are being returned. If I just use df$dim1a.dim2c.dim3b, I get a list of the actual attribute values for those objects, which is what I am looking for.
+++
If this is not easily feasible or not recommended for some reason, can something like melting/casting also be performed on a SpatialLinesDataFrame?
I'm trying to modify a "variable" variable; that is to say, I wish to modify only that variable whose name matches the text in a cell of a dataframe/matrix.
For example, if matrix1[1,1] == "Rupert", I want to perform an operation on the variable Rupert (say, Rupert <- Rupert + 1). But if matrix1[1,1] == "Paddington", I want to perform the operation on the Paddington variable instead.
I've discovered the assign() function which allows me create new variables whose name is that of the text in a matrix, but I haven't been able to figure out how to modify variables in a similar fashion.
Thanks for your attention,
Alistair
Using your example:
var <- matrix1[1,1]
assign(var,get(var)+1)
The get function can be found in the "See also" section of help(assign).
I am using the tabular() function to produce tables in r (tables library).
I want to compute CI's from the data in the output (let mytable be the output from tabular()). Simple enough I thought, except when I go to call a value from the matrix, I get the error Error in mytable[1, i] - 1 : non-numeric argument to binary operator. I thought this was odd, as when I call up a particular cell of the matrix (where as.matrix returned true for mytable), for example mytable[1, i] for some i, I get an interger. I then do the as.list for mytable and get true also, so I am not sure what this means. I guess the tabular() function stores the results as a special kind of matrix.
I am only trying to pull out the mean,sdev, and n, which I am able to just by typing the cell location, for example mytable[1, i] would return an 86. However, when I try to call up the value in qt(.975,df=(mytable[1,i]-1)) for example, I get the error above. Not sure really how to approach this except to manually enter the values into another matrix (which I would like to avoid). Or, if I can compute CI's directly in the tabular() function that would work also. Cheers.
I shall quote for you the Value section of the documentation on the function ?tabular:
An object of S3 class "tabular". This is a matrix of mode list, whose
entries are computed summary values, with the following attributes:
rowLabels - A matrix of labels for the rows. This will have the same
number of rows as the main matrix, but may have multiple columns for
different nested levels of labels. If a label covers multiple rows, it
is entered in the first row, and NA is used to fill following rows.
colLabels - Like rowLabels, but labelling the columns.
table - The original table expression being displayed. A list of the
original format specifications are attached as a "fmtlist" attribute.
formats - A matrix of the same shape as the main result, containing NA
for default formatting, or an index into the format list.
As the documentation says, each element of the matrix is a list. If your tabular object is called tab type tab[1,1] and you should see a list containing one of your table values. If I wanted to modify that value, I would probably do something like:
tab[1,1]$term <- value
just like you would modify values in any other list.
Type attributes(tab) and you'll see the items listed above, containing a lot of the formatting information and row/col headers.
Suppose that I have a cell, lets say Sheet2.A1, with the value: Sheet1.A10.
It contains the information from where to fetch the data.
Now I would like to fetch this data, which I do with INDIRECT(Sheet2.A1). However, I would further like to extract the data from some cells below in the same column. So suppose I would like to extract data from Sheet1.A11 and Sheet1.A12.
How can I calculate this offset to extract the data?
Is there any extension to the INDIRECT function where I can add this offset of one or two columns below?
I resolved it using =OFFSET(INDIRECT(Sheet2.A1),1,0) and =OFFSET(INDIRECT(Sheet2.A1),2,0)