I have a dataset like by inserting a new column of data between 1st column
M1 M2 M3 M4
G1 1 2 3 4
G2 4 3 2 1
...
G120 1 3 4 2
I would like to modify dataset with another column of data in vim to
M1 M2 M3 M4
G1 1 1 2 3 4
G2 1 4 3 2 1
...
G120 1 1 3 4 2
i assume you use \t to align your text. then regex can be used
:%s/^\(G\d\+\)/\1\t1/
Vim's blockwise visual mode, ctrl-v, is probably the best way to do this.
In particular, you should use "Visual-block Insert" (vim help: :help v_b_I)
With your example, with the cursor at |1| in normal mode:
M1 M2 M3 M4
G1 |1| 2 3 4
G2 4 3 2 1
...
G120 1 3 4 2
Do the following:
ctrl-v - start visual blockwise selection
3j - extend selection 3 lines down (can substitute any other movement command here)
I - begin block insert mode
1<space><space><space><space><space> - the text you want inserted every line
Esc or ctrl-[ (its synonym) - complete the visual-block insert
Visual block insert can also be used to indent/unindent multiple lines, append text to every line (even if they don't end on the same column), etc, etc.
Related
In vim 8, ctrl+A / crtl+X increases and decreases number for visual selected columns, respectively.
1
2
3
ctrl+A
2
3
4
However, both are not worked to multiple columns.
Is there any simple method to increase/decrease a constant number for all columns selected? Like,
1 10
2 11
3 12
Any commands
2 11
3 12
4 13
Not exactly what you asked for but might be close enough:
CTRL-V and select all the columns you want to change.
Do CTRL-A. This will increment the numbers of the first column. At this point, the cursor should be at the top of the first column.
Do w to move the cursor to the second column.
Do . to increment the second column.
Keep doing w and . until you're done with all the columns.
This also works if you only select one column in step 1, but only if all the columns have the same width or if the selected column is the widest.
This may not work correctly if the columns do not have the same number of rows.
Using command line and submatch:
:%s/\d\+/\=submatch(0)+1/g
I have an excel table formatted(with header row included just for reference) like so:
1
2
3
4
5
1
2
3
4
5
5
2
2
5
2
2
-
2
I would like it formatted as text like so:
522 522 -2
Whenever I paste into word and convert to text it prints a space in between cells that are adjacent like this (underline as space):
5_2_2_ 5_2_2 _ -_2
I also tried pasting into other text editors and VScode without success.
I have several lines of this data and it's actually longer than the example so it's fairly cumbersome to manually delete the spaces. I'm wondering if there's a way to do this in excel/word.
In EXCEL sheet I have 1728 rows and 2 columns (L and O). I am doing addition of these 2 columns in column P. Further I want to count the occurrence in this column if addition is EQUAL to 2 or 4 or 6 or 8 BUT condition here is that The COUNT should be such that BOTH the columns L and O are EQUAL and Their addition is either 2 or 4 or 6 or 8.
This means that only the columns in L and O with values "1+1" , "2+2", "3+3", "4+4" should be counted. The addition of "1+3", "4+2" should not be counted.
=COUNTIF(P:P,4)
does not work.
L O P M
===========================
1 1 2 1 (NO OF 2'S)
2 2 4 1 (NO OF 4'S)
3 3 6 1 (NO OF 6'S)
1 3 4* NO TO BE COUNTED
4 4 8 1 (NO OF 8'S)
2 4 6* NOT TO BE COUNTED
4 2 6*
AS SEEN ABOVE RESULT OF COUNTING IS STORED IN M. Let me know the formula
=IF(L29=M29,SUMPRODUCT(--($L$29:$L$35=$M$29:$M$35)*(L29=$L$29:$L$35)),"Not Counted")
My data started in row 29 so you will need to adjust the references. It counts the entire table in 1 shot. So if you added a row to the bottom that had 1 and 1 and 2, the results in column M in your first row would become 2 and the same for the row you just added.
Will this formula help...?
=IF(AND(A1=B1,OR(SUM(A1,B1)=2,SUM(A1,B1)=4,SUM(A1,B1)=6,SUM(A1,B1)=8)),SUM(A1,B1),"NOT TO BE COUNTED")
Just drag the formula till you have data. You will need to adjust the references.
Here is the reference data.
I have a line of numbers from 0 to 100. They follow each other like usual:
1 2 3 4 5 6 7 8 9 10 ... and so on --> ... 100
But I need to change their direction from right to left, like this:
100 <-- and so on ... 10 9 8 7 6 5 4 3 2 1 0
Is there some special tool for this operetion?
Each number is in its individual cell and horizontally: 1 in [A1], 2 in [B1], 3 in [C1], and so on.
If this is exaclty what you need, you can simply enter 100 in A1, 99 in B1, select the 2 cells and drag the formula to the right (by clicking on the little square at the bottom right of the selected range).
If your actual problem is a bit more complex and you need to sort the data in descending order, you could:
transpose it to make it vertical (Copy / Paste Special and select transpose)
sort the data set with the standard sorting feature
transpose it again back to its original range
I'm not sure how to ask this question without illustrating it, so here goes:
I have results from a test which has tested peoples attitudes (scores 1-5) to different voices on a 16 different scales. The data set looks like this (where P1,P2,P3 are participants, A, B, C are voices)
Aformal Apleasant Acool Bformal etc
P1 2 3 1 4
P2 5 4 2 4
P3 1 2 4 3
However, I want to rearrange my data to look like this:
formal pleasant cool
P1A 3 3 5
P1B 2 1 6
P1C etc
P1D
This would mean a lot more rows (multiple rows per participant), and a lot fewer columns. Is it doable without having to manually reenter all the scores in a new excel file?
Sure, no problem. I just hacked this solution:
L M N O P Q
person# voice# formal pleasant cool
1 1 P1A 2 3 1
1 2 P1B 4 5 2
1 3 P1C 9 9 9
2 1 P2A 5 4 2
2 2 P2B 4 4 1
2 3 P2C 9 9 9
3 1 P3A 1 2 4
3 2 P3B 3 3 2
3 3 P3C 9 9 9
Basically, in columns L and M, I made two columns with index numbers. Voice numbers go from 1 to 3 and repeat every 3 rows because there are nv=3 voices (increase this if you have voices F, G, H...). Person numbers are also repeated for 3 rows each, because there are nv=3 voices.
To make the row headers (P1A, etc.), I used this formula: ="P" & L2 & CHAR(64+M2) at P1A and copied down.
To make the new table of values, I used this formula: =OFFSET(B$2,$L2-1,($M2-1)*3) at P1A-formal, and copied down and across. Note that B$2 corresponds to the cell address for P1-Aformal in the original table of values (your example).
I've used this indexing trick I don't know how many times to quickly rearrange tables of data inherited from other people.
EDIT: Note that the index columns are also made (semi)automatically using a formula. The first nv=3 rows are made manually, and then subsequent rows refer to them. For example, the formula in L5 is =L2+1 and the formula in M5 is =M2. Both are copied down to the end of the table.