Counting different values in a column in access 2010 - ms-access-2010

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];

Related

if i want to sort a column by size in rstudio, how do i make sure that the associated values of the rows sort with the column?

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

To find if the group of elements is a substring of another string in R or SAS ?

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

working with data in tables in R

I'm a newbie at working with R. I've got some data with multiple observations (i.e., rows) per subject. Each subject has a unique identifier (ID) and has another variable of interest (X) which is constant across each observation. The number of observations per subject differs.
The data might look like this:
ID Observation X
1 1 3
1 2 3
1 3 3
1 4 3
2 1 4
2 2 4
3 1 8
3 2 8
3 3 8
I'd like to find some code that would:
a) Identify the number of observations per subject
b) Identify subjects with greater than a certain number of observations (e.g., >= 15 observations)
c) For subjects with greater than a certain number of observations, I'd like to to manipulate the X value for each observation (e.g., I might want to subtract 1 from their X value, so I'd like to modify X for each observation to be X-1)
I might want to identify subjects with at least three observations and reduce their X value by 1. In the above, individuals #1 and #3 (ID) have at least three observations, and their X values--which are constant across all observations--are 3 and 8, respectively. I want to find code that would identify individuals #1 and #3 and then let me recode all of their X values into a different variable. Maybe I just want to subtract 1 from each X value. In that case, the code would then give me X values of (3-1=)2 for #1 and 7 for #3, but #2 would remain at X = 4.
Any suggestions appreciated, thanks!
You can use the aggregate function to do this.
a) Say your table is named temp, you can find the total number of observations for each ID and x column by using the SUM function in aggregate:
tot =aggregate(Observation~ID+x, temp,FUN = sum)
The output will look like this:
ID x Observation
1 1 3 10
2 2 4 3
3 3 8 6
b) To see the IDs that are over a certain number, you can create a subset of the table, tot.
vals = tot$ID[tot$Observation>5]
Output is:
[1] 1 3
c) To change the values that were found in (b) you reference the subsetted data, where the number of observations is > 5, and then update those values.
tot$x[vals] = tot$x[vals]+1
The final output for the table is
ID x Observation
1 1 4 10
2 2 4 3
3 3 9 6
To change the original table, you can subset the table by the IDs you found
temp[temp$ID %in% vals,]$x = temp[temp$ID %in% vals,]$x + 1
a) Identify the number of observations per subject
you can use this code on each variable:
summary

How to calculate percentage from each row of two different columns in R

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

Get averages of specific columns in a table using sqlite

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

Resources