Is there any way to automatically paste text vertically into google sheets? - database

I have about 10 years worth of data from a local animal shelter and I need to copy all kittens under 3 months over from Excel spreadsheets onto a google sheet, their ID, age in days, month of intake, intake year, sex, and intake type . I am doing this for a research project, it has to just be the data points and nothing else. The aggregate looks like this.
I look through the excel spreadsheets and type the relevant data onto notepad. All the data points I need are separated by date with all the kittens taken in on that date, with their age, sex and ID number corresponding to the order they're in so I can find discrepancies easily and input the data in quickly, it usually turns out looking like this:
(3/14) 74 M A25164093
(3/18) 34 27 34 M F M A25192748 A25192760 A25192795
(3/19) 70 F A25202463
(3/20) 80 2 1 1 F F F F A25208017 A25210624 A25210625 A25210626
My main bottleneck is putting it into the data aggregate. I have to go cell by cell inputting this data into the columns and I feel like there has to be a way to copy the data I need vertically onto the columns they belong in.
I've tried the transpose function and it seems to perfectly match what I need, however it requires the data points transposed vertically to already be somewhere on the google sheet, and if I try and delete the cell with the function so it's just the data it transposed it also deletes all the data it tranposed vertically. It seems to only function to display the data. This is not ideal, I need something that just copy and pastes data into the columns they belong in so that it can be useable.
This is an old sample of the data aggregate (output):
https://docs.google.com/spreadsheets/d/1pUaU4ChFHwL9suqAGRUegBQ72F1-rusp/edit?usp=sharing&ouid=115130932279005924436&rtpof=true&sd=true
And this is a sample of the input:
(5/2) 10 10 10 M F F A27729208 A27729210 A27729212 (5/3) 26 30 26 30 9 9 9 9 2 9 9 M M F F M M M F F F F A27732515 A27732516 A27732518 A27732520 A27732521 A27732541 A27732542 A27732543 A27732545 A27732546 A27732547 A27732549 (5/4) 29 54 54 40 61 M M F M A27735990 A27735996 A27736005 A27740796 (5/4) 29 54 54 40 61 M M F M A27735990 A27735996 A27736005 A27740796 (5/6) 26 26 16 26 14 33 21 21 F F F F M M U U A27760967 A27760970 A27760973 A27760977 A27761539 A27761720 A27762164 A27762169 (5/7) 21 21 F M A27767085 A27767091 (5/8) 47 51 52 51 F F M M A27779894 A27782370 A27782371 A27782373 (5/9) 19 60 60 36 67 67 M F M F F F A27787353 A27788037 A27788043 A27788687 A27788911 A27788923 (5/11) 47 47 47 28 F M M M A27798156 A27798165 A27798168 A27801540 (5/12) 20 10 27 27 52 F M M M F A27810744 A27811484 A27812447 A27812449 A27818279 (5/14) 21 21 21 U U U A27829238 A27829239 A27829241

I don't know exactly how your input looks. But if you need to paste transposed, you have a specific function in Sheets by copying and right-clicking:
Select "Transposed" and it will look like this:

Related

What is a correct name for an operation that turns 3-column long table into a compact "2D" table with variable number of columns?

For example, from this table
row
col
val
0
A
32
0
B
31
0
C
35
1
A
30
1
B
29
1
C
29
2
A
15
2
B
14
2
D
18
3
A
34
3
B
39
3
C
34
3
D
35
it should produce this table:
A
B
C
D
0
32
31
35
1
30
29
29
2
15
14
18
3
34
39
34
35
Is there some official, canonical (or at least popular specific unambiguous) term for such operation (or its reverse)?
I am trying to find (or implement & publish) a tool that transforms CSV this way, but am unsure what to search for (or how to name it).
The term is pivot.
Some databases have native support for pivot, eg SQL Server's PIVOT (and even UNPIVOT) keywords.
For most databases you must craft a query that does the job.

How do I subset data set with specific condition?

I have a dataset that has ages of children. I want to subset the variables that correspond to a certain bracket of age.
basically if I have a dataset
data = names age marks attendance
A 5 1 90
B 12 9 87
C 16 7 98
D 3 0 70
E 7 4 77
I want this:
df = names age (2-10) marks attendance
A 5 1 90
D 3 0 70
E 7 4 77
And similarly for the age bracket 11-16

How to get the 3rd column in an array by using 1st and 2nd column values as index in Matlab

I have an array with three columns like this:
A B C
10 75 20
30 67 50
85 12 30
98 49 70
I have A and B values, and I want to get the corresponding C value.
For example if I enter (30,67) it should display 50.
Does Matlab have any trick for getting C value?
(my dataset is very large, and I need a fast way)
you can use ismember:
ABC = [10 75 20
30 67 50
85 12 30
98 49 70];
q = [30 67
85 12];
[~, locb] = ismember( q, ABC(:,1:2), 'rows' );
C = ABC(locb,3);
The result you get is
C =
50
30
Note that the code assume all pairs in q can be found in ABC.
Let your input data be defined as
data = [ 10 75 20
30 67 50
85 12 30
98 49 70];
values = [ 30 67];
This should be pretty fast:
index = data(:,1)==values(1) & data(:,2)==values(2); %// logical index to matching rows
result = data(index,3); %// third-column value for those rows
This gives all third-column values that match, should there be more than one.
If you want to specify several pairs of values at once, and obtain all matching results:
index = any(bsxfun(#eq, data(:,1).', values(:,1)), 1) & ...
any(bsxfun(#eq, data(:,2).', values(:,2)), 1);
result = data(index,3);
For example, given
data = [ 10 75 20
30 67 50
85 12 30
98 49 70
30 67 80 ];
values = [ 30 67
98 49];
the result would be
result =
50
70
80
You can create a sparse matrix. This solution only works if C does not contain any zeros and A and B are integers larger 0
A = [10 30 85 98]';
B = [75 67 12 49]';
C = [20 50 30 70]';
S = sparse(A,B,C);
S(10,75) % returns corresponding C-Value if found, 0 otherwise.
Try accumarray:
YourMatrix = accumarray([A B],C,[],#mean,true);
This way YourMatrix will be a matrix of size [max(A) max(B)], with the values of C at YourMatrix(A(ind),B(ind)), with ind the desired index of A and B:
A = [10 30 85 98]';
B = [75 67 12 49]';
C = [20 50 30 70]';
YourMatrix = accumarray([A B],C,[],#mean,true);
ind = 2;
YourMatrix(A(ind),B(ind))
ans =
50
This way, when there is a repetition in A B, it will return the corresponding C value, provided each unique pair of A B has the same C value. The true flag makes accumarray output a sparse matrix as opposed to a full matrix.

Retrieving specific elements in matlab from arrays in MATLAB

I have an array in MATLAB
For example
a = 1:100;
I want to select the first 4 element in every successive 10 elements.
In this example I want to b will be
b = [1,2,3,4,11,12,13,14, ...]
can I do it without for loop?
I read in the internet that i can select the element for each step:
b = a(1:10:end);
but this is not working for me.
Can you help me?
With reshape
%// reshaping your matrix to nx10 so that it has successive 10 elements in each row
temp = reshape(a,10,[]).'; %//'
%// taking first 4 columns and reshaping them back to a row vector
b = reshape(temp(:,1:4).',1,[]); %//'
Sample Run for smaller size (although this works for your actual dimensions)
a = 1:20;
>> b
b =
1 2 3 4 11 12 13 14
To vectorize the operation you must generate the indices you wish to extract:
a = 1:100;
b = a(reshape(bsxfun(#plus,(1:4)',0:10:length(a)-1),[],1));
Let's break down how this works. First, the bsxfun function. This performs a function, here it is addition (#plus) on each element of a vector. Since you want elements 1:4 we make this one dimension and the other dimension increases by tens. this will lead a Nx4 matrix where N is the number of groups of 4 we wish to extract.
The reshape function simply vectorizes this matrix so that we can use it to index the vector a. To better understand this line, try taking a look at the output of each function.
Sample Output:
>> b = a(reshape(bsxfun(#plus,(1:4)',0:10:length(a)-1),[],1))
b =
Columns 1 through 19
1 2 3 4 11 12 13 14 21 22 23 24 31 32 33 34 41 42 43
Columns 20 through 38
44 51 52 53 54 61 62 63 64 71 72 73 74 81 82 83 84 91 92
Columns 39 through 40
93 94

How can I create an array of ratios inside a for loop in MATLAB?

I would like to create an array or vector of musical notes using a for loop. Every musical note, A, A#, B, C...etc is a 2^(1/12) ratio of the previous/next. E.G the note A is 440Hz, and A# is 440 * 2^(1/12) Hz = 446.16Hz.
Starting from 27.5Hz (A0), I want a loop that iterates 88 times to create an array of each notes frequency up to 4186Hz, so that will look like
f= [27.5 29.14 30.87 ... 4186.01]
So far, I've understood this much:
f = [];
for i=1:87,
%what goes here
% f = [27.5 * 2^(i/12)]; ?
end
return;
There is no need to do a loop for this in matlab, you can simply do:
f = 27.5 * 2.^((0:87)/12)
The answer:
f =
Columns 1 through 13
27.5 29.135 30.868 32.703 34.648 36.708 38.891 41.203 43.654 46.249 48.999 51.913 55
Columns 14 through 26
58.27 61.735 65.406 69.296 73.416 77.782 82.407 87.307 92.499 97.999 103.83 110 116.54
Columns 27 through 39
123.47 130.81 138.59 146.83 155.56 164.81 174.61 185 196 207.65 220 233.08 246.94
Columns 40 through 52
261.63 277.18 293.66 311.13 329.63 349.23 369.99 392 415.3 440 466.16 493.88 523.25
Columns 53 through 65
554.37 587.33 622.25 659.26 698.46 739.99 783.99 830.61 880 932.33 987.77 1046.5 1108.7
Columns 66 through 78
1174.7 1244.5 1318.5 1396.9 1480 1568 1661.2 1760 1864.7 1975.5 2093 2217.5 2349.3
Columns 79 through 88
2489 2637 2793.8 2960 3136 3322.4 3520 3729.3 3951.1 4186
maxind = 87;
f = zeros(1, maxind); % preallocate, better performance and avoids mlint warnings
for ii=1:maxind
f(ii) = 27.5 * 2^(ii/12);
end
The reason I named the loop variable ii is because i is the name of a builtin function. So it's considered bad practice to use that as a variable name.
Also, in your description you said you want to iterate 88 times, but the above loop only iterates 1 through 87 (both inclusive). If you want to iterate 88 times change maxind to 88.

Resources