mean

r search along a vector and calculate the mean

Deadly 提交于 2019-12-23 13:31:45
问题 I have data that looks like: require(data.table) DT <- data.table(x=c(19,19,19,21,21,19,19,22,22,22), y=c(53,54,55,32,44,45,49,56,57,58)) I would like to search along x, and calculate the means for y. However, when using. DT[, .(my=mean(y)), by=.(x)] I get the overall means for the coinciding values of x. I would like to search along x, and each time x changes, I would like to calculate a new mean. For the provided example, the output would be: DTans <- data.table(x=c(19,21,19,22), my=c(54,38

How to sort two fields with mongoose?

青春壹個敷衍的年華 提交于 2019-12-23 04:59:15
问题 I'm trying to allow users to see trending posts. The general idea is to sort by the most recent posts (_id: -1) and then sort those by most upvotes (upvotes_count: -1) and then limiting the results (.limit(3)). This is a bit simplified, so please ignore this implementation of "trending posts". Unfortunately, I'm not able to return two sorts in the way that I want. So with a collection of six posts, it returns the most recent three, but it doesn't then sort them by most upvotes. For instance:

Timeseries average based on a defined time interval (bin)

佐手、 提交于 2019-12-23 04:29:06
问题 Here is an example of my dataset. I want to calculate bin average based on time (i.e., ts) every 10 seconds. Could you please provide some hints so that I can carry on? In my case, I want to average time (ts) and Var in every 10 seconds. For example, I will get an averaged value of Var and ts from 0 to 10 seconds; I will get another averaged value of Var and ts from 11 to 20 seconds, etc. df = data.frame(ts = seq(1,100,by=0.5), Var = runif(199,1, 10)) Any functions or libraries in R can I use

C# calculate mean of the values in int array

本秂侑毒 提交于 2019-12-23 03:34:13
问题 What's the problem when I try to print the average of the values in int array and it prints out something totally different as many times as I have values. int[] numbers; numbers = new int[5]; Console.WriteLine("give five integer numbers:"); numbers[0] = Int32.Parse(Console.ReadLine()); numbers[1] = Int32.Parse(Console.ReadLine()); numbers[2] = Int32.Parse(Console.ReadLine()); numbers[3] = Int32.Parse(Console.ReadLine()); numbers[4] = Int32.Parse(Console.ReadLine()); int sum = 0; foreach (int

r get mean of n columns by row

≯℡__Kan透↙ 提交于 2019-12-23 03:12:56
问题 I have a simple data.frame > df <- data.frame(a=c(3,5,7), b=c(5,3,7), c=c(5,6,4)) > df a b c 1 3 5 5 2 5 3 6 3 7 7 4 Is there a simple and efficient way to get a new data.frame with the same number of rows but with the mean of, for example, column a and b by row? something like this: mean.of.a.and.b c 1 4 5 2 4 6 3 7 4 回答1: Use rowMeans() on the first two columns only. Then cbind() to the third column. cbind(mean.of.a.and.b = rowMeans(df[-3]), df[3]) # mean.of.a.and.b c # 1 4 5 # 2 4 6 # 3 7

how to calculate the mean of list of list of matrices in r

对着背影说爱祢 提交于 2019-12-23 02:55:17
问题 I have a list like below, which is a list of lists containing matrices(so "ftable" is a list of ten lists and each of the internal lists contains seven matrices). I need to calculate the mean of associated matrices which may also have NA values as well.I have tried several ways but I got errors. for(i in 1:10){ for(j in 1:7){ ftable[[i]][[j]] <- matrix (x,nrow=8,ncol=8, byrow=TRUE) } } > str(ftable) List of 10 $ :List of 7 ....... ....... as the result I need to have a list containing seven

案例:逻辑回归Logistic Regression做乳腺癌预测

谁都会走 提交于 2019-12-23 00:30:15
使用逻辑回归算法解决乳腺癌检测问题,使用sk-learn自带的乳腺癌数据集 1 导入数据 from sklearn . datasets import load_breast_cancer cancer = load_breast_cancer ( ) X = cancer . data y = cancer . target print ( 'data shape:{0};positive:{1},negative:{2}' . format ( X . shape , y [ y == 1 ] . shape , y [ y == 0 ] . shape ) ) print ( '腺癌数据的前两行为:' ) print ( cancer . data [ 0 : 2 ] ) data shape:(569, 30);positive:(357,),negative:(212,) 腺癌数据的前两行为: [[ 1.79900000e+01 1.03800000e+01 1.22800000e+02 1.00100000e+03 1.18400000e-01 2.77600000e-01 3.00100000e-01 1.47100000e-01 2.41900000e-01 7.87100000e-02 1.09500000e+00 9.05300000e-01 8

Average of multiple files in shell

一世执手 提交于 2019-12-22 05:58:30
问题 I want to calculate the average of 15 files:- ifile1.txt, ifile2.txt, ....., ifile15.txt. Number of columns and rows of each file are same. Part of the data looks as ifile1.txt ifile2.txt ifile3.txt 3 5 2 2 . 1 2 1 3 . 4 3 4 1 . 1 4 2 1 . 1 3 0 2 . 5 3 1 5 . 4 6 5 2 . 2 5 5 1 . 3 4 3 1 . 5 5 7 1 . 0 0 1 1 . 4 3 4 0 . . . . . . . . . . . . . . . . I would like to find over a new file which will show the average of these 15 fils. ofile.txt 2.66 3.33 2.33 2 . (i.e. average of 3 1 4, average of 5

Column-Wise Standard Deviation in OpenCV

核能气质少年 提交于 2019-12-22 05:39:44
问题 Is there a direct way to compute the column-wise standard deviation for a matrix in opencv? Similar to std in Matlab. I've found one for the mean: cv::Mat col_mean; reduce(A, col_mean, 1, CV_REDUCE_AVG); but I cannot find such a function for the standard deviation. 回答1: Here's a quick answer to what you're looking for. I added both the standard deviation and mean for each column. The code can easily be modified for rows. cv::Mat A = ...; // FILL IN THE DATA FOR YOUR INPUT MATRIX cv::Mat

computing column sums of matrix vector<vector<double> > with iterators?

﹥>﹥吖頭↗ 提交于 2019-12-22 05:25:23
问题 In a previous post column vector with row means -- with std::accumulate? I asked if it was possible, using STL functionality, to compute row means of a matrix vector< vector<double> > data ( rows, vector<double> ( columns ) ); The top answer by @benjaminlindley is not only just what I was looking for, it is a thing of beauty. Forever hopeful I thought it would be as easy to compute column means, so an STL equivalent of vector<double> colmeans( data[0].size() ); for ( int i=0; i<data.size(); i