I have a basic sqlite table with about 10 columns. The first column is a text name, while the rest are just integers. I was hoping to form a new table that has one row for each of the distinct values in the first row, and every other column be an average of all the instances of that column. For example if I have the below table:
foo 1 3 5
bar 3 4 1
edd 2 1 3
bar 1 4 2
foo 1 1 3
Then I would want to create a new table with three rows (foo, bar, edd), and the row would have the average of each column for those rows. Is this possible using sqlite?
foo 1 2 4
bar 2 2.5 1.5
edd 2 1 3
Try
select col1, avg(col2), avg(col3), avg(col4)
from mytable
group by col1
Related
I have a data.frame with 1200 rows and 5 columns, where each row contains 5 values of one person. now i need to sort one column by size but I want the remaining columns to sort with the column, so that one column is sorted by increasing values and the other columns contain the values of the right persons. ( So that one row still contains data from one and the same person)
colnames(BAPlotDET) = c("fsskiddet", "fspiddet","avg", "diff","absdiff")
these are the column names of my data.frame and I wanna sort it by the column called "avg"
First of all, please always provide us with a reproducible example such as below. The sorting of a data frame by default sorts all columns.
vector <- 1:3
BAPlotDET <- data.frame(vector, vector, vector, vector, vector)
colnames(BAPlotDET) = c("fsskiddet", "fspiddet","avg", "diff","absdiff")
fsskiddet fspiddet avg diff absdiff
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
BAPlotDET <- BAPlotDET[order(-BAPlotDET$avg),]
> BAPlotDET
fsskiddet fspiddet avg diff absdiff
3 3 3 3 3 3
2 2 2 2 2 2
1 1 1 1 1 1
I want to find if the given elements under a group are the part of another string or no ? If they are then I want the group number of the string where it was the part. They should be part of another string.For example, 'Benefits, verify' is one string under group 1 and that is part of group 2 string (claims,verify,benefits,verify). I also want to count how many times it appears in another string.
For example
Column1 group
Benefits,verify 1
claims,verify,benefits,verify 2
inquiry,type 3
claims,verify 4
Output expected:
column1 Part of group count
Benefits, verify 2 1
claims,verify 2 1
inquiry,type - -
claims,verify,benefits,verify - -
You can use lavenshtein's distance:
a = which(!`diag<-`(adist(dat$Column1,partial=T,ignore.case = T),NA),T)
merge(dat,aggregate(count~.,data.frame(a,count=1),sum),by.x="group",by.y="row",all=T)
group Column1 col count
1 1 Benefits,verify 2 1
2 2 claims,verify,benefits,verify NA NA
3 3 inquiry,type NA NA
4 4 claims,verify 2 1
I've inserted a table to make it clearer, basically, I'm trying to find a way to get rid of other columns that are identical in the values it has to another one, a duplicate column.
As we can see in the image, Col 2 and 4 are identical, I want to remove Col 4, because for my use it's not helping and is unneeded data.
Thanks!
We can use duplicated on the transpose of the dataset to create a logical index and use that to subset the columns
df1[!duplicated(t(df1))]
# Col1 Col2 Col3 Col5
#1 1 2 3 1
#2 2 3 4 2
#3 3 4 1 4
#4 4 1 2 3
I have a column in Access table and it has different values, i just want to count number of records against each different value e.g
Column A Count
4 3
4 3
4 3
3 2
3 2
1 1
Can anyone help me how to do this?
You do it using a query:
SELECT [Column A], Count([Column A]) AS CountOfColumnA
FROM tbl
GROUP BY [Column A];
please let me know how to calculate percentage from row wise in R.As i'm using prop.table function but it is not giving me solution
empid presentdays empid absentdays
1 5 1 10
2 2 2 4
3 6 3 12
I want to calculate percentage with respect to each empid as their performance
empid presentdays empid absentdays perfom%
1 5 1 10 50
2 2 2 4 50
how to do it in R as i've tried prop.table() function also but it doesn't work
Assuming your dataframe is called df:
df$perform <- df$presentdays/df$absentdays*100