Creating multiple Dataframes from a multidimensional array of matrices - arrays

I have a huge number of matrices (over 50) included in a single array.
Each of my matrices represents a year (1951,1952, and so on).
Each matrix contains observations of 4 plants at 80 locations.
Consequently each matrix has 4 columns and 80 rows.
I want to rearrange my data into 4 dataframes.
One Dataframe for each plant, meaning the dimensions of my array (the different years) become my colnames and the different locations become my rownames.
1951
10 12 13 24
2 NA NA NA 288
3 114 139 NA 287
4 104 128 NA 285
5 105 128 NA 289
6 107 123 NA 282
7 112 121 NA 289
8 110 130 NA 287
9 112 128 NA 290
10 107 125 NA 284
. . . . .
. . . . .
1952
10 12 13 24
2 45 34 345 45
3 345 139 NA 287
4 104 128 345 285
5 105 128 NA 289
6 137 123 NA 282
7 112 141 123 239
8 110 130 NA 287
9 112 128 123 230
10 307 125 NA 284
. . . . .
. . . . .
Is there any quick way to do this?
This would be of great advantage for my following calculations!

Suppose we have the 9x4x2 array a shown reproducibly in the Note at the end. Then we can use apply to get a list of data frames from it. Replace 2 with 1 or 3 to get other variations.
apply(a, 2, as.data.frame)
giving:
$`10`
1951 1952
2 45 45
3 345 345
4 104 104
5 105 105
6 137 137
7 112 112
8 110 110
9 112 112
10 307 307
$`12`
1951 1952
2 34 34
3 139 139
4 128 128
5 128 128
6 123 123
7 141 141
8 130 130
9 128 128
10 125 125
$`13`
1951 1952
2 345 345
3 NA NA
4 345 345
5 NA NA
6 NA NA
7 123 123
8 NA NA
9 123 123
10 NA NA
$`14`
1951 1952
2 45 45
3 287 287
4 285 285
5 289 289
6 282 282
7 239 239
8 287 287
9 230 230
10 284 284
Note
a <- array(data = c(45L, 345L, 104L, 105L, 137L, 112L, 110L, 112L, 307L, 34L, 139L,
128L, 128L, 123L, 141L, 130L, 128L, 125L, 345L, NA, 345L, NA,
NA, 123L, NA, 123L, NA, 45L, 287L, 285L, 289L, 282L, 239L, 287L,
230L, 284L, 45L, 345L, 104L, 105L, 137L, 112L, 110L, 112L, 307L,
34L, 139L, 128L, 128L, 123L, 141L, 130L, 128L, 125L, 345L, NA,
345L, NA, NA, 123L, NA, 123L, NA, 45L, 287L, 285L, 289L, 282L,
239L, 287L, 230L, 284L),
dim = c(9, 4, 2),
dimnames = list(c("2", "3", "4", "5", "6", "7", "8", "9", "10"), c("10",
"12", "13", "14"), c("1951", "1952"))
)

I made some small example data called years_dfs for the thing you are trying to achieve. It should also work if you use a list of matrices instead of data frames.
library(tidyverse)
years <- 1951:1953
year_dfs <- list(data.frame(a = 1:5, b = 6:10),
data.frame(a = 11:15, b = 16:20),
data.frame(a = 21:25, b = 26:30)) %>%
`names<-`(years)
year_dfs
$`1951`
a b
1 1 6
2 2 7
3 3 8
4 4 9
5 5 10
$`1952`
a b
1 11 16
2 12 17
3 13 18
4 14 19
5 15 20
$`1953`
a b
1 21 26
2 22 27
3 23 28
4 24 29
5 25 30
lapply(1:ncol(year_dfs[[1]]), function(plant)
lapply(1:length(year_dfs), function(year)
year_dfs[[year]][,plant]) %>%
as.data.frame %>%
`colnames<-`(years)
) %>% `names<-`(colnames(year_dfs[[1]]))
$a
1951 1952 1953
1 1 11 21
2 2 12 22
3 3 13 23
4 4 14 24
5 5 15 25
$b
1951 1952 1953
1 6 16 26
2 7 17 27
3 8 18 28
4 9 19 29
5 10 20 30

Related

Adding Character String with Numbers / Concatenate Number with String in Matlab Array

How to add character ',' or '+' in a matlab 2d array.
I've tried the following way.
clc
clear all
close all
min=0;
max=1052;
random_int = randi([min max],5,10)
% random_int=[515,586,942,742;353,588,916,436]
% load('Random_Int_x.mat')
% random_int
[m,n]=size(random_int);
for i=1:1:m
allOneString = sprintf('%d,' , random_int(i,:));
allOneString= allOneString(1:end-1)% strip final comma
Str_1(i,:)=allOneString
% allOneString= strjoin(arrayfun(#(x) num2str(x),random_int(i,:),'UniformOutput',false),',');
end
Str_1
Example of Input / Matrix
random_int =
2 9 7 7 9 8 2 5 7 5
6 1 9 9 6 1 9 4 1 0
5 0 8 8 5 6 9 0 4 6
0 9 9 8 7 5 6 3 7 8
8 4 2 0 5 5 1 8 2 6
Output:
Str_1 =
5×19 char array
'2,9,7,7,9,8,2,5,7,5'
'6,1,9,9,6,1,9,4,1,0'
'5,0,8,8,5,6,9,0,4,6'
'0,9,9,8,7,5,6,3,7,8'
'8,4,2,0,5,5,1,8,2,6'
This works properly with random number between 0-9.. However if I put input above 9 --> 10 .. then matlab throws matrix dimension error.
Subscripted assignment dimension mismatch.
Error in Number_with_String (line 14)
Str_1(i,:)=allOneString;
For Input above 9:
random_int =
76 96 88 23 26 25 92 5 61 86
87 69 32 36 86 39 46 21 55 69
42 26 56 69 55 97 91 78 76 41
74 74 24 3 46 52 29 70 88 4
7 48 13 69 15 12 79 91 90 24
Expecting output:
'76,96,88,23,26,25,92,5,61,86'
'87,69,32,36,86,39,46,21,55,69' ... etc
Any suggestion to resolve this ..
Here's a way:
random_int = randi([0 500],5,10); % example data
y = mat2cell(random_int, ones(1,size(random_int,1)), size(random_int,2)); % split into rows
y = cellfun(#(x) sprintf('%i,', x), y, 'UniformOutput', false); % strings with commas
y = cellfun(#(s) s(1:end-1), y, 'UniformOutput', false); % remove last comma from each
Example result:
>> y
y =
5×1 cell array
'74,281,294,376,124,203,211,170,242,334'
'488,268,31,84,404,74,205,178,215,20'
'120,242,390,37,113,199,140,375,395,469'
'455,94,115,476,28,20,365,213,181,31'
'130,62,138,421,261,105,114,226,398,90'
I would recommend you use string which shipped in 16b. You can convert the result to char or cellstr if you need.
>> min=0; max=1052;
>> random_int = randi([min max],5,10)
random_int =
532 145 857 264 616 793 558 494 327 688
736 157 256 648 578 400 820 12 556 725
938 271 978 498 965 597 983 354 174 787
1010 885 368 370 300 79 136 170 633 474
576 267 207 874 797 56 598 836 276 88
>> str = join(string(random_int),',')
str =
5×1 string array
"532,145,857,264,616,793,558,494,327,688"
"736,157,256,648,578,400,820,12,556,725"
"938,271,978,498,965,597,983,354,174,787"
"1010,885,368,370,300,79,136,170,633,474"
"576,267,207,874,797,56,598,836,276,88"
>> char(str)
ans =
5×39 char array
'532,145,857,264,616,793,558,494,327,688'
'736,157,256,648,578,400,820,12,556,725 '
'938,271,978,498,965,597,983,354,174,787'
'1010,885,368,370,300,79,136,170,633,474'
'576,267,207,874,797,56,598,836,276,88 '
clc
clear all
close all
min=0;
max=1052;
random_int = randi([min max],200,10);
[m,n]=size(random_int);
for i=1:1:m
allOneString = sprintf('%d,' , random_int(i,:));
allOneString= allOneString(1:end-1); % strip final comma
Str_1{i}=allOneString;
end
Str_1=Str_1'

Segmentation fault : Reading values from a text file

In my code I am trying to read values from a .txt file so as to build my adjacency matrix but it keeps on returning a segmentation fault. I don't seem to be able to point out where I am going wrong. Please help.
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <math.h>
#include <limits.h>
#include <iostream>
#define MAX_VERTICES 1024
int global_adj_matrix[MAX_VERTICES][MAX_VERTICES];
int **graph_tree;
int **node_data;
int global_weight;
int number_threads;
int max_nodes;
int random_node;
int max_weight;
int finish_flag;
void readAdjMatrix();
int main(int argc, char *argv[]){
for(int i = 0 ; i < MAX_VERTICES ; i++){
for(int j = 0 ; j < MAX_VERTICES ; j++){
global_adj_matrix[i][j] = 0;
}
}
number_threads = atoi(argv[1]);
max_nodes = 0;
readAdjMatrix();
}
void readAdjMatrix(){
int source, destination, edge_weight;
max_nodes = INT_MIN;
max_weight = INT_MIN;
FILE *file_pointer = fopen("graph.txt", "r");
while(!feof(file_pointer)){
fscanf(file_pointer, "%d", &source);
fscanf(file_pointer, "%d", &destination);
fscanf(file_pointer, "%d", &edge_weight);
global_adj_matrix[source][destination] = edge_weight;
global_adj_matrix[destination][source] = edge_weight;
if(edge_weight > max_weight)
max_weight = edge_weight;
if(destination > max_nodes)
max_nodes = destination;
}
printf("%d %d", max_weight, max_nodes);
for(int i = 0 ; i <= max_nodes ; i++){
for(int j = 0 ; j <= max_nodes ; j++){
printf("%d\t", global_adj_matrix[i][j]);
}
printf("\n");
}
fclose(file_pointer);
}
This is my .txt file
0 1 281
0 2 242
0 3 344
0 4 340
0 5 372
0 6 161
0 7 49
0 8 278
0 10 190
0 11 213
0 12 55
0 13 239
0 14 321
0 15 162
1 0 281
1 2 249
1 3 58
1 4 331
1 5 189
1 6 84
1 7 259
1 9 256
1 11 188
1 12 149
1 13 330
1 14 17
1 15 370
2 0 242
2 1 249
2 3 125
2 4 179
2 5 355
2 6 11
2 7 232
2 8 199
2 9 67
2 10 390
2 12 312
2 13 3
2 14 237
2 15 96
3 0 344
3 1 58
3 2 125
3 4 105
3 5 192
3 6 180
3 7 335
3 8 280
3 9 185
3 10 66
3 11 65
3 13 274
3 14 72
3 15 282
4 0 340
4 1 331
4 2 179
4 3 105
4 5 149
4 6 286
4 7 265
4 8 359
4 9 341
4 10 211
4 11 367
4 12 340
4 13 14
4 14 69
4 15 128
5 0 372
5 1 189
5 2 355
5 3 192
5 4 149
5 6 167
5 7 268
5 8 20
5 9 270
5 10 210
5 11 369
5 12 131
5 13 133
5 15 167
6 0 161
6 1 84
6 2 11
6 3 180
6 4 286
6 5 167
6 7 208
6 8 335
6 9 353
6 10 12
6 11 307
6 12 199
6 13 273
6 14 118
7 0 49
7 1 259
7 2 232
7 3 335
7 4 265
7 5 268
7 6 208
7 8 182
7 9 327
7 10 272
7 11 198
7 12 103
7 13 132
7 15 161
8 0 278
8 2 199
8 3 280
8 4 359
8 5 20
8 6 335
8 7 182
8 9 108
8 10 112
8 11 344
8 12 192
8 13 264
8 14 207
8 15 231
9 1 256
9 2 67
9 3 185
9 4 341
9 5 270
9 6 353
9 7 327
9 8 108
9 10 395
9 11 205
9 12 365
9 13 8
9 14 57
9 15 132
10 0 190
10 2 390
10 3 66
10 4 211
10 5 210
10 6 12
10 7 272
10 8 112
10 9 395
10 11 11
10 12 7
10 13 288
10 14 143
10 15 226
11 0 213
11 1 188
11 3 65
11 4 367
11 5 369
11 6 307
11 7 198
11 8 344
11 9 205
11 10 11
11 12 203
11 13 136
11 14 252
11 15 168
12 0 55
12 1 149
12 2 312
12 4 340
12 5 131
12 6 199
12 7 103
12 8 192
12 9 365
12 10 7
12 11 203
12 13 90
12 14 344
12 15 11
13 0 239
13 1 330
13 2 3
13 3 274
13 4 14
13 5 133
13 6 273
13 7 132
13 8 264
13 9 8
13 10 288
13 11 136
13 12 90
13 14 39
13 15 39
14 0 321
14 1 17
14 2 237
14 3 72
14 4 69
14 6 118
14 8 207
14 9 57
14 10 143
14 11 252
14 12 344
14 13 39
14 15 154
15 0 162
15 1 370
15 2 96
15 3 282
15 4 128
15 5 167
15 7 161
15 8 231
15 9 132
15 10 226
15 11 168
15 12 11
15 13 39
15 14 154
Your segmentation fault is because you're trying to read a nonexistent index in the argument vector of main. If you want to avoid that, you should rewrite it to match something like this:
int main (int argc, const char *argv[]) {
if (argc > 1 && (number_threads = atoi(argv[1]))) {
max_nodes = 0;
readAdjMatrix();
}
return 0;
}
This ensures that you have an argument to convert to begin with, and also that it is a nonzero number. I believe atoi has undefined behavior if it isn't a valid string though, so you should harden against that. You also do some other unnecessary things. For one, this block here:
for(int i = 0 ; i < MAX_VERTICES ; i++){
for(int j = 0 ; j < MAX_VERTICES ; j++){
global_adj_matrix[i][j] = 0;
}
}
is pointless because if you initialize a 2D array as an external/global variable then it is automatically zeroed upon initialization. Only local/automatic variables will be filled with garbage data. Therefore, you can omit it.
Finally, I would also change your while loop to look more or less like this (Credit: Chux for better loop guard).
while(fscanf(file_pointer, "%d %d %d", &source, &destination, &edge_weight) == 3) {
global_adj_matrix[source][destination] = global_adj_matrix[destination][source] = edge_weight;
if(edge_weight > max_weight)
max_weight = edge_weight;
if(destination > max_nodes)
max_nodes = destination;
}
This ensures you correctly scanned the amount of variables necessary per line. And the extended assignment just saves a bit of room.
Hope this fixed the problem you were having.
I am posting my answer by neglecting the bigger code which you have not mentioned in your question. I have trimmed down the unnecessary code. The code is given below.
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#define MAX_VERTICES 1024
int global_adj_matrix[MAX_VERTICES][MAX_VERTICES];
int global_weight,max_nodes,random_node,max_weight;
void readAdjMatrix();
int main()
{
int i,j;
max_nodes = 0;
readAdjMatrix();
return 0;
}
void readAdjMatrix()
{
int source, destination, edge_weight,i,j;
max_nodes = INT_MIN;
max_weight = INT_MIN;
FILE *file_pointer = fopen("graph.txt", "r");
while(!feof(file_pointer))
{
fscanf(file_pointer, "%d", &source);
fscanf(file_pointer, "%d", &destination);
fscanf(file_pointer, "%d", &edge_weight);
global_adj_matrix[source][destination] = global_adj_matrix[destination][source] =edge_weight;
if(destination > max_nodes)
max_nodes = destination;
}
printf( "%d\n", max_nodes);
for( i = 0 ; i <= max_nodes ; i++){
for( j = 0 ; j <= max_nodes ; j++){
printf("%d\t", global_adj_matrix[i][j]);
}
printf("\n");
}
fclose(file_pointer);
}
PS : Simply execute this code with ./a.out with no command line argument. In case you are using the command line argument (as given in your question), please use the following syntax to execute your code :
./a.out "your desired number which works with the bigger code"

reading and printing a .csv file like a 2D matrix with both integer and float values in c

Reading a file in c with .csv as extension. The file consisting of both integer and float type data values. Is there any way to read the csv file. Any help is appreciated.
The data is as follows:
Application_No. Actual_Effort (in PM) No of Processes No of Tasks No of partnerLinks Task Variables Element Variables Event Variables Script Developer's Skills Developer's Confidence TPSS TS TCC
1 918.28 1 3 5 33 7 2 3 3.5 1 8 135 143
2 8891.513 3 9 3 100 15 6 12 3 1 36 1197 1233
3 22479.261 5 15 23 125 25 10 20 3 1 190 2700 2890
4 2961.131 2 4 9 70 13 4 17 2 0 72 416 488
5 19650.198 7 14 19 130 28 12 5 2.5 0 231 2450 2681
6 377.75 1 2 4 22 8 2 2 3 1 6 68 74
7 2671.93 1 5 12 55 12 6 4 2 0 17 385 402
8 966.15 3 3 6 31 8 5 7 2.5 0 27 153 180
9 3765.81 2 6 17 73 14 2 3 3.5 1 46 552 590
10 7467.11 4 8 21 87 19 13 1 2 0 116 960 1076

Cachegrind's cg_annotate does not display annotation for my source code

My source code:
$ cat play.c
int main() {
return 0;
}
Building and running cachegrind on it:
$ gcc -g -Wall play.c -o play && valgrind --tool=cachegrind --cachegrind-out-file=out ./play
==17670== Cachegrind, a cache and branch-prediction profiler
==17670== Copyright (C) 2002-2012, and GNU GPL'd, by Nicholas Nethercote et al.
==17670== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==17670== Command: ./play
==17670==
--17670-- warning: L3 cache found, using its data for the L2 simulation.
==17670==
==17670== I refs: 97,846
==17670== I1 misses: 697
==17670== LLi misses: 692
==17670== I1 miss rate: 0.71%
==17670== LLi miss rate: 0.70%
==17670==
==17670== D refs: 36,490 (25,595 rd + 10,895 wr)
==17670== D1 misses: 1,657 ( 1,185 rd + 472 wr)
==17670== LLd misses: 1,503 ( 1,043 rd + 460 wr)
==17670== D1 miss rate: 4.5% ( 4.6% + 4.3% )
==17670== LLd miss rate: 4.1% ( 4.0% + 4.2% )
==17670==
==17670== LL refs: 2,354 ( 1,882 rd + 472 wr)
==17670== LL misses: 2,195 ( 1,735 rd + 460 wr)
==17670== LL miss rate: 1.6% ( 1.4% + 4.2% )
And finally, running cg_annotate:
$ cg_annotate out play.c
--------------------------------------------------------------------------------
I1 cache: 65536 B, 64 B, 2-way associative
D1 cache: 65536 B, 64 B, 2-way associative
LL cache: 6291456 B, 64 B, 48-way associative
Command: ./play
Data file: out
Events recorded: Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
Events shown: Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
Event sort order: Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
Thresholds: 0.1 100 100 100 100 100 100 100 100
Include dirs:
User annotated: play.c
Auto-annotation: off
--------------------------------------------------------------------------------
Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
--------------------------------------------------------------------------------
97,846 697 692 25,595 1,185 1,043 10,895 472 460 PROGRAM TOTALS
--------------------------------------------------------------------------------
Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw file:function
--------------------------------------------------------------------------------
22,411 13 13 7,443 157 130 3,653 1 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-lookup.c:do_lookup_x
17,322 10 10 3,596 87 83 1,828 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-lookup.c:_dl_lookup_symbol_x
15,697 19 19 3,594 557 543 1,927 245 238 /build/eglibc-TepTGA/eglibc-2.17/elf/../sysdeps/x86_64/dl-machine.h:_dl_relocate_object
9,072 2 2 2,694 17 11 0 0 0 /build/eglibc-TepTGA/eglibc-2.17/string/../sysdeps/x86_64/multiarch/../strcmp.S:strcmp
8,262 13 13 2,053 84 70 119 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/do-rel.h:_dl_relocate_object
4,118 6 6 1,732 17 15 497 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-lookup.c:check_match.9345
1,201 2 2 197 0 0 2 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-minimal.c:strsep
1,149 36 36 301 1 1 138 10 10 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-load.c:_dl_map_object_from_fd
1,139 14 14 377 14 13 158 13 13 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-version.c:_dl_check_map_versions
1,057 31 31 223 1 1 110 2 2 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-deps.c:_dl_map_object_deps
1,008 13 13 252 11 11 76 3 3 /build/eglibc-TepTGA/eglibc-2.17/string/../string/memcmp.c:bcmp
922 67 67 200 22 13 112 10 10 /build/eglibc-TepTGA/eglibc-2.17/elf/rtld.c:dl_main
779 2 2 201 6 0 116 2 2 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-misc.c:_dl_name_match_p
742 5 5 75 1 1 0 0 0 /build/eglibc-TepTGA/eglibc-2.17/string/../sysdeps/x86_64/multiarch/../rtld-strlen.S:strlen
727 4 4 114 10 10 0 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-cache.c:_dl_cache_libcmp
606 4 4 114 0 0 112 1 1 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-minimal.c:__libc_memalign
586 11 11 96 3 3 111 21 21 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-object.c:_dl_new_object
549 8 8 96 14 14 47 12 12 /build/eglibc-TepTGA/eglibc-2.17/elf/get-dynamic-info.h:_dl_map_object_from_fd
520 11 11 113 6 6 83 3 3 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-load.c:open_verify
512 10 10 19 5 4 295 37 37 /build/eglibc-TepTGA/eglibc-2.17/string/../sysdeps/x86_64/multiarch/../memset.S:memset
458 11 11 135 16 0 112 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-reloc.c:_dl_relocate_object
450 24 24 89 1 1 73 3 3 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-load.c:_dl_map_object
408 11 11 113 16 14 26 4 4 /build/eglibc-TepTGA/eglibc-2.17/elf/../elf/dl-sysdep.c:_dl_sysdep_start
377 5 5 54 2 1 39 3 3 /build/eglibc-TepTGA/eglibc-2.17/string/../sysdeps/x86_64/memcpy.S:mempcpy
369 5 5 59 0 0 47 6 6 /build/eglibc-TepTGA/eglibc-2.17/string/../sysdeps/x86_64/multiarch/../memcpy.S:memcpy
349 14 14 38 2 2 63 6 6 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-load.c:_dl_init_paths
344 2 2 117 25 25 2 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-environ.c:_dl_next_ld_env_entry
325 3 3 5 0 0 292 36 36 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-tls.c:_dl_allocate_tls_storage
317 16 16 49 10 10 27 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-cache.c:_dl_load_cache_lookup
311 14 14 105 0 0 42 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-load.c:open_path
270 11 11 86 5 0 33 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-fini.c:_dl_fini
266 11 11 46 6 6 20 7 7 /build/eglibc-TepTGA/eglibc-2.17/elf/get-dynamic-info.h:_dl_start
257 20 20 46 0 0 39 3 3 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-hwcaps.c:_dl_important_hwcaps
234 8 8 34 6 6 23 6 6 /build/eglibc-TepTGA/eglibc-2.17/elf/get-dynamic-info.h:dl_main
232 4 4 73 14 0 35 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-init.c:call_init
211 1 1 63 11 11 19 5 5 /build/eglibc-TepTGA/eglibc-2.17/elf/../sysdeps/x86_64/dl-machine.h:_dl_start
207 2 2 18 3 3 0 0 0 /build/eglibc-TepTGA/eglibc-2.17/string/../sysdeps/x86_64/multiarch/../strchr.S:index
185 5 5 72 4 4 27 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-version.c:match_symbol
181 7 7 49 1 0 25 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-fini.c:_dl_sort_fini
175 17 13 83 1 0 21 1 1 ???:???
175 6 6 20 4 2 19 6 6 /build/eglibc-TepTGA/eglibc-2.17/elf/rtld.c:_dl_start
168 10 10 18 2 2 6 0 0 /build/eglibc-TepTGA/eglibc-2.17/string/../sysdeps/x86_64/multiarch/../cacheinfo.c:handle_amd
156 6 6 56 1 0 18 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/../elf/dl-runtime.c:_dl_fixup
146 2 2 30 5 5 0 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/do-rel.h:_dl_start
137 11 11 30 0 0 34 2 2 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-load.c:fillin_rpath
125 14 14 11 1 0 29 4 2 /build/eglibc-TepTGA/eglibc-2.17/string/../sysdeps/x86_64/multiarch/../cacheinfo.c:init_cacheinfo
111 3 3 36 0 0 51 5 5 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-error.c:_dl_catch_error
106 3 3 26 0 0 20 0 0 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-object.c:_dl_add_to_namespace_list
100 2 2 28 5 5 24 1 1 /build/eglibc-TepTGA/eglibc-2.17/elf/dl-lookup.c:_dl_setup_hash
--------------------------------------------------------------------------------
-- User-annotated source: play.c
--------------------------------------------------------------------------------
No information has been collected for play.c
Why No information has been collected for play.c? I would expect to see that if I didn't build with debug symbols, but I did.
In case it's relevant, this is Debian "jessie", with GCC 4.8.1, and Valgrind 3.8.1.
It's not enough to specify the source file I want annotated as a relative path, so none of the following 2 commands would work:
$ cg_annotate out play.c
$ cg_annotate out ./play.c
It has to be an absolute path:
$ cg_annotate out ~/projects/utils/play.c
[snip]
--------------------------------------------------------------------------------
-- User-annotated source: /home/tshepang/projects/utils/play.c
--------------------------------------------------------------------------------
Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
2 0 0 0 0 0 1 0 0 int main() {
1 0 0 0 0 0 0 0 0 return 0;
2 0 0 2 0 0 0 0 0 }
[snip]
Note that callgrind_annotate will only work when called the following way (assuming, of course, that we ran Valgrind with callgrind tool instead of cachegrind):
$ callgrind_annotate out play.c
The other two forms (./play.c and ~/projects/utils/play.c) do not work, making this a UX bug.

Average of Counts

I Have a table called totals and the data looks like:
ACC_ID Data_ID Mon Weeks Total_AR_Count Total_FR_Count Total_OP_Count
23 9 01/2011 4 172 251 194
42 9 01/2011 4 2 16 28
75 9 01/2011 4 33 316 346
75 9 07/2011 5 1 12 20
42 9 09/2011 5 25 758 25
I want the output to be as Average of all the counts grouped by ACC_ID and Data_ID:
ACC_ID Data_ID Avg_AR_Count Avg_FR_Count Avg_OP_Count
23 9 172 251 194
42 9 13.5 387 26.5
75 9 17 164 183
How can do this?
Your description of what you want just about writes the SQL:
SELECT ACC_ID, Data ID, AVG(Total_AR_Count) AS Avg_AR_Count, AVG(Total_FR_Count) AS Avg_FR_Count...
FROM table
GROUP BY ACC_ID, Data_ID

Resources