how to assign values of the column for given conditional statements
up vote
0
down vote
favorite
I need a script to assign values of the column with a given conditional argument. To be specific, here is my data and my condition
input data.file:
0.4
3.6
-2.4
0.1
-2.0
1.6
2.2
3.6
condition: assign R if data.file greater than 2(>2), assign S if data.file less than -2(<-2), and assign M if data.file greater than or equal to-2 and less than or equal to 2 [-2,2].
Desired output file out.file
0.4 M
3.6 R
-2.4 S
0.1 M
-2.0 M
1.6 M
2.2 R
3.6 R
text-processing awk columns
add a comment |
up vote
0
down vote
favorite
I need a script to assign values of the column with a given conditional argument. To be specific, here is my data and my condition
input data.file:
0.4
3.6
-2.4
0.1
-2.0
1.6
2.2
3.6
condition: assign R if data.file greater than 2(>2), assign S if data.file less than -2(<-2), and assign M if data.file greater than or equal to-2 and less than or equal to 2 [-2,2].
Desired output file out.file
0.4 M
3.6 R
-2.4 S
0.1 M
-2.0 M
1.6 M
2.2 R
3.6 R
text-processing awk columns
1
so what's the problem? have you tried anything? Stack Overflow might be a good place to ask programming specific questions.
– umläute
Sep 18 '13 at 11:08
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need a script to assign values of the column with a given conditional argument. To be specific, here is my data and my condition
input data.file:
0.4
3.6
-2.4
0.1
-2.0
1.6
2.2
3.6
condition: assign R if data.file greater than 2(>2), assign S if data.file less than -2(<-2), and assign M if data.file greater than or equal to-2 and less than or equal to 2 [-2,2].
Desired output file out.file
0.4 M
3.6 R
-2.4 S
0.1 M
-2.0 M
1.6 M
2.2 R
3.6 R
text-processing awk columns
I need a script to assign values of the column with a given conditional argument. To be specific, here is my data and my condition
input data.file:
0.4
3.6
-2.4
0.1
-2.0
1.6
2.2
3.6
condition: assign R if data.file greater than 2(>2), assign S if data.file less than -2(<-2), and assign M if data.file greater than or equal to-2 and less than or equal to 2 [-2,2].
Desired output file out.file
0.4 M
3.6 R
-2.4 S
0.1 M
-2.0 M
1.6 M
2.2 R
3.6 R
text-processing awk columns
text-processing awk columns
edited 2 days ago
Rui F Ribeiro
38.2k1475123
38.2k1475123
asked Sep 18 '13 at 10:59
AiB
3472620
3472620
1
so what's the problem? have you tried anything? Stack Overflow might be a good place to ask programming specific questions.
– umläute
Sep 18 '13 at 11:08
add a comment |
1
so what's the problem? have you tried anything? Stack Overflow might be a good place to ask programming specific questions.
– umläute
Sep 18 '13 at 11:08
1
1
so what's the problem? have you tried anything? Stack Overflow might be a good place to ask programming specific questions.
– umläute
Sep 18 '13 at 11:08
so what's the problem? have you tried anything? Stack Overflow might be a good place to ask programming specific questions.
– umläute
Sep 18 '13 at 11:08
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
read your file line by line, check whether the value falls into a given category and output accordingly.
awk '{if($1>2)print $1,"R"; else if ($1<-2)print $1,"S"; else print $1,"M"}'
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
read your file line by line, check whether the value falls into a given category and output accordingly.
awk '{if($1>2)print $1,"R"; else if ($1<-2)print $1,"S"; else print $1,"M"}'
add a comment |
up vote
3
down vote
read your file line by line, check whether the value falls into a given category and output accordingly.
awk '{if($1>2)print $1,"R"; else if ($1<-2)print $1,"S"; else print $1,"M"}'
add a comment |
up vote
3
down vote
up vote
3
down vote
read your file line by line, check whether the value falls into a given category and output accordingly.
awk '{if($1>2)print $1,"R"; else if ($1<-2)print $1,"S"; else print $1,"M"}'
read your file line by line, check whether the value falls into a given category and output accordingly.
awk '{if($1>2)print $1,"R"; else if ($1<-2)print $1,"S"; else print $1,"M"}'
answered Sep 18 '13 at 11:13
umläute
4,5381433
4,5381433
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f91224%2fhow-to-assign-values-of-the-column-for-given-conditional-statements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
so what's the problem? have you tried anything? Stack Overflow might be a good place to ask programming specific questions.
– umläute
Sep 18 '13 at 11:08