Replace Values in Vector on Specific Place in R The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsHow far from a specific state in a Markov chainHow to replace levels with certain value?Reducing the effect of down voters with rating systemHow to replace the missing values in Age column from Titanic/kaggle projectConvergence in Hartigan-Wong k-means method and other algorithmschange detectionSome algorithms and approach for identification of specific patterns?How to replace NA values with another value in factors in R?how to I replace numeric values with a string in an R dataframe?SVM model classifying into one class only, after standardization
Does Parliament hold absolute power in the UK?
A pet rabbit called Belle
Relations between two reciprocal partial derivatives?
Windows 10: How to Lock (not sleep) laptop on lid close?
Was credit for the black hole image misattributed?
Create an outline of font
How are presidential pardons supposed to be used?
Can smartphones with the same camera sensor have different image quality?
"... to apply for a visa" or "... and applied for a visa"?
Is this wall load bearing? Blueprints and photos attached
Arduino Pro Micro - switch off LEDs
Take groceries in checked luggage
Is a pteranodon too powerful as a beast companion for a beast master?
University's motivation for having tenure-track positions
Can a 1st-level character have an ability score above 18?
How is simplicity better than precision and clarity in prose?
How do you keep chess fun when your opponent constantly beats you?
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
He got a vote 80% that of Emmanuel Macron’s
Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?
Why can't wing-mounted spoilers be used to steepen approaches?
how can a perfect fourth interval be considered either consonant or dissonant?
When did F become S? Why?
Empty set is subset of every set? If yes, why that...
Replace Values in Vector on Specific Place in R
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsHow far from a specific state in a Markov chainHow to replace levels with certain value?Reducing the effect of down voters with rating systemHow to replace the missing values in Age column from Titanic/kaggle projectConvergence in Hartigan-Wong k-means method and other algorithmschange detectionSome algorithms and approach for identification of specific patterns?How to replace NA values with another value in factors in R?how to I replace numeric values with a string in an R dataframe?SVM model classifying into one class only, after standardization
$begingroup$
I want to make $5^th$,$10^th$,$15^th$,$20^th$ and $25^th$ values of vector an outlier in all xs by using x1 [5]+OT1,x1 [10]+OT1 and so on. For this purpose I have made this R code,
n=25
x1<-runif(n,0,1)
x2<-runif(n,0,1)
x3<-runif(n,0,1)
x4<-runif(n,0,1)
x<-data.frame(x1,x2,x3,x4)
OT1<-mean(x1)+100
OT2<-mean(x2)+100
OT3<-mean(x3)+100
OT4<-mean(x4)+100
I have tried command replace() and also modify(), but none of them replace them at once at least in one vector. Kindly help me in this manner.
Edit
by using comment of @user2974951 I tried this
x1[seq(5,25,5)]=x1[seq(5,25,5)]+100
Nx1<-replace(x1,x1==x1[5],x1 [5]+OT1)
x2[seq(5,25,5)]=x2[seq(5,25,5)]+100
Nx2<-replace(x2,x2==x2[5],x1 [5]+OT2)
x3[seq(5,25,5)]=x3[seq(5,25,5)]+100
Nx3<-replace(x3,x3==x3[5],x3 [5]+OT3)
x4[seq(5,25,5)]=x4[seq(5,25,5)]+100
Nx4<-replace(x4,x4==x4[5],x4 [5]+OT4)
Nx<-data.frame(Nx1,Nx2,Nx3,Nx4)
but its not working well
Results
Nx1 Nx2 Nx3 Nx4
1 0.46815292 0.08606537 0.3307899 4.362630e-01
2 0.59723633 0.12122892 0.4819987 7.753236e-01
3 0.56219881 0.25936144 0.4990369 8.125097e-03
4 0.58366209 0.90552595 0.7368288 9.701722e-01
5 201.53593455 201.43976570 201.2130687 2.014071e+02
6 0.05521220 0.61975750 0.8296397 9.942981e-02
7 0.99058967 0.59373303 0.1156678 2.632295e-01
8 0.96428154 0.41710719 0.2547667 4.605275e-01
9 0.49978441 0.98922281 0.7526796 6.978671e-01
10 100.63831600 100.24166490 100.1790951 1.009707e+02
11 0.42694764 0.67506156 0.3142930 8.022078e-02
12 0.76015772 0.93265460 0.5734483 2.417875e-01
13 0.92832414 0.95247906 0.2578651 2.536677e-01
14 0.38818813 0.47634761 0.7163780 4.091937e-01
15 100.95118175 100.35951345 100.5519005 1.007286e+02
16 0.34262275 0.42573721 0.7594048 2.707246e-01
17 0.91930401 0.33828510 0.2679736 7.299545e-01
18 0.45901144 0.95876530 0.6419959 9.764771e-01
19 0.08840004 0.34092442 0.7492228 5.148988e-01
20 100.63958996 100.25792655 100.1351512 1.007377e+02
21 0.81191203 0.88845305 0.6504586 6.138992e-01
22 0.05737578 0.27700759 0.1193294 9.060633e-01
23 0.72447661 0.41372855 0.3055600 5.396204e-01
24 0.47942584 0.71890752 0.4814340 3.924752e-01
25 100.68191347 100.11710451 100.0443692 1.002326e+02
Why observation $5^th$ is 200+ and no outlier in $x4$???
r statistics outlier
$endgroup$
bumped to the homepage by Community♦ 36 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
$begingroup$
I want to make $5^th$,$10^th$,$15^th$,$20^th$ and $25^th$ values of vector an outlier in all xs by using x1 [5]+OT1,x1 [10]+OT1 and so on. For this purpose I have made this R code,
n=25
x1<-runif(n,0,1)
x2<-runif(n,0,1)
x3<-runif(n,0,1)
x4<-runif(n,0,1)
x<-data.frame(x1,x2,x3,x4)
OT1<-mean(x1)+100
OT2<-mean(x2)+100
OT3<-mean(x3)+100
OT4<-mean(x4)+100
I have tried command replace() and also modify(), but none of them replace them at once at least in one vector. Kindly help me in this manner.
Edit
by using comment of @user2974951 I tried this
x1[seq(5,25,5)]=x1[seq(5,25,5)]+100
Nx1<-replace(x1,x1==x1[5],x1 [5]+OT1)
x2[seq(5,25,5)]=x2[seq(5,25,5)]+100
Nx2<-replace(x2,x2==x2[5],x1 [5]+OT2)
x3[seq(5,25,5)]=x3[seq(5,25,5)]+100
Nx3<-replace(x3,x3==x3[5],x3 [5]+OT3)
x4[seq(5,25,5)]=x4[seq(5,25,5)]+100
Nx4<-replace(x4,x4==x4[5],x4 [5]+OT4)
Nx<-data.frame(Nx1,Nx2,Nx3,Nx4)
but its not working well
Results
Nx1 Nx2 Nx3 Nx4
1 0.46815292 0.08606537 0.3307899 4.362630e-01
2 0.59723633 0.12122892 0.4819987 7.753236e-01
3 0.56219881 0.25936144 0.4990369 8.125097e-03
4 0.58366209 0.90552595 0.7368288 9.701722e-01
5 201.53593455 201.43976570 201.2130687 2.014071e+02
6 0.05521220 0.61975750 0.8296397 9.942981e-02
7 0.99058967 0.59373303 0.1156678 2.632295e-01
8 0.96428154 0.41710719 0.2547667 4.605275e-01
9 0.49978441 0.98922281 0.7526796 6.978671e-01
10 100.63831600 100.24166490 100.1790951 1.009707e+02
11 0.42694764 0.67506156 0.3142930 8.022078e-02
12 0.76015772 0.93265460 0.5734483 2.417875e-01
13 0.92832414 0.95247906 0.2578651 2.536677e-01
14 0.38818813 0.47634761 0.7163780 4.091937e-01
15 100.95118175 100.35951345 100.5519005 1.007286e+02
16 0.34262275 0.42573721 0.7594048 2.707246e-01
17 0.91930401 0.33828510 0.2679736 7.299545e-01
18 0.45901144 0.95876530 0.6419959 9.764771e-01
19 0.08840004 0.34092442 0.7492228 5.148988e-01
20 100.63958996 100.25792655 100.1351512 1.007377e+02
21 0.81191203 0.88845305 0.6504586 6.138992e-01
22 0.05737578 0.27700759 0.1193294 9.060633e-01
23 0.72447661 0.41372855 0.3055600 5.396204e-01
24 0.47942584 0.71890752 0.4814340 3.924752e-01
25 100.68191347 100.11710451 100.0443692 1.002326e+02
Why observation $5^th$ is 200+ and no outlier in $x4$???
r statistics outlier
$endgroup$
bumped to the homepage by Community♦ 36 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
$begingroup$
Something likex[seq(5,25,5)]=x[seq(5,25,5)]+100?
$endgroup$
– user2974951
Oct 5 '18 at 10:22
$begingroup$
@user2974951 Kindly see my edit.
$endgroup$
– Angel
Oct 6 '18 at 3:23
add a comment |
$begingroup$
I want to make $5^th$,$10^th$,$15^th$,$20^th$ and $25^th$ values of vector an outlier in all xs by using x1 [5]+OT1,x1 [10]+OT1 and so on. For this purpose I have made this R code,
n=25
x1<-runif(n,0,1)
x2<-runif(n,0,1)
x3<-runif(n,0,1)
x4<-runif(n,0,1)
x<-data.frame(x1,x2,x3,x4)
OT1<-mean(x1)+100
OT2<-mean(x2)+100
OT3<-mean(x3)+100
OT4<-mean(x4)+100
I have tried command replace() and also modify(), but none of them replace them at once at least in one vector. Kindly help me in this manner.
Edit
by using comment of @user2974951 I tried this
x1[seq(5,25,5)]=x1[seq(5,25,5)]+100
Nx1<-replace(x1,x1==x1[5],x1 [5]+OT1)
x2[seq(5,25,5)]=x2[seq(5,25,5)]+100
Nx2<-replace(x2,x2==x2[5],x1 [5]+OT2)
x3[seq(5,25,5)]=x3[seq(5,25,5)]+100
Nx3<-replace(x3,x3==x3[5],x3 [5]+OT3)
x4[seq(5,25,5)]=x4[seq(5,25,5)]+100
Nx4<-replace(x4,x4==x4[5],x4 [5]+OT4)
Nx<-data.frame(Nx1,Nx2,Nx3,Nx4)
but its not working well
Results
Nx1 Nx2 Nx3 Nx4
1 0.46815292 0.08606537 0.3307899 4.362630e-01
2 0.59723633 0.12122892 0.4819987 7.753236e-01
3 0.56219881 0.25936144 0.4990369 8.125097e-03
4 0.58366209 0.90552595 0.7368288 9.701722e-01
5 201.53593455 201.43976570 201.2130687 2.014071e+02
6 0.05521220 0.61975750 0.8296397 9.942981e-02
7 0.99058967 0.59373303 0.1156678 2.632295e-01
8 0.96428154 0.41710719 0.2547667 4.605275e-01
9 0.49978441 0.98922281 0.7526796 6.978671e-01
10 100.63831600 100.24166490 100.1790951 1.009707e+02
11 0.42694764 0.67506156 0.3142930 8.022078e-02
12 0.76015772 0.93265460 0.5734483 2.417875e-01
13 0.92832414 0.95247906 0.2578651 2.536677e-01
14 0.38818813 0.47634761 0.7163780 4.091937e-01
15 100.95118175 100.35951345 100.5519005 1.007286e+02
16 0.34262275 0.42573721 0.7594048 2.707246e-01
17 0.91930401 0.33828510 0.2679736 7.299545e-01
18 0.45901144 0.95876530 0.6419959 9.764771e-01
19 0.08840004 0.34092442 0.7492228 5.148988e-01
20 100.63958996 100.25792655 100.1351512 1.007377e+02
21 0.81191203 0.88845305 0.6504586 6.138992e-01
22 0.05737578 0.27700759 0.1193294 9.060633e-01
23 0.72447661 0.41372855 0.3055600 5.396204e-01
24 0.47942584 0.71890752 0.4814340 3.924752e-01
25 100.68191347 100.11710451 100.0443692 1.002326e+02
Why observation $5^th$ is 200+ and no outlier in $x4$???
r statistics outlier
$endgroup$
I want to make $5^th$,$10^th$,$15^th$,$20^th$ and $25^th$ values of vector an outlier in all xs by using x1 [5]+OT1,x1 [10]+OT1 and so on. For this purpose I have made this R code,
n=25
x1<-runif(n,0,1)
x2<-runif(n,0,1)
x3<-runif(n,0,1)
x4<-runif(n,0,1)
x<-data.frame(x1,x2,x3,x4)
OT1<-mean(x1)+100
OT2<-mean(x2)+100
OT3<-mean(x3)+100
OT4<-mean(x4)+100
I have tried command replace() and also modify(), but none of them replace them at once at least in one vector. Kindly help me in this manner.
Edit
by using comment of @user2974951 I tried this
x1[seq(5,25,5)]=x1[seq(5,25,5)]+100
Nx1<-replace(x1,x1==x1[5],x1 [5]+OT1)
x2[seq(5,25,5)]=x2[seq(5,25,5)]+100
Nx2<-replace(x2,x2==x2[5],x1 [5]+OT2)
x3[seq(5,25,5)]=x3[seq(5,25,5)]+100
Nx3<-replace(x3,x3==x3[5],x3 [5]+OT3)
x4[seq(5,25,5)]=x4[seq(5,25,5)]+100
Nx4<-replace(x4,x4==x4[5],x4 [5]+OT4)
Nx<-data.frame(Nx1,Nx2,Nx3,Nx4)
but its not working well
Results
Nx1 Nx2 Nx3 Nx4
1 0.46815292 0.08606537 0.3307899 4.362630e-01
2 0.59723633 0.12122892 0.4819987 7.753236e-01
3 0.56219881 0.25936144 0.4990369 8.125097e-03
4 0.58366209 0.90552595 0.7368288 9.701722e-01
5 201.53593455 201.43976570 201.2130687 2.014071e+02
6 0.05521220 0.61975750 0.8296397 9.942981e-02
7 0.99058967 0.59373303 0.1156678 2.632295e-01
8 0.96428154 0.41710719 0.2547667 4.605275e-01
9 0.49978441 0.98922281 0.7526796 6.978671e-01
10 100.63831600 100.24166490 100.1790951 1.009707e+02
11 0.42694764 0.67506156 0.3142930 8.022078e-02
12 0.76015772 0.93265460 0.5734483 2.417875e-01
13 0.92832414 0.95247906 0.2578651 2.536677e-01
14 0.38818813 0.47634761 0.7163780 4.091937e-01
15 100.95118175 100.35951345 100.5519005 1.007286e+02
16 0.34262275 0.42573721 0.7594048 2.707246e-01
17 0.91930401 0.33828510 0.2679736 7.299545e-01
18 0.45901144 0.95876530 0.6419959 9.764771e-01
19 0.08840004 0.34092442 0.7492228 5.148988e-01
20 100.63958996 100.25792655 100.1351512 1.007377e+02
21 0.81191203 0.88845305 0.6504586 6.138992e-01
22 0.05737578 0.27700759 0.1193294 9.060633e-01
23 0.72447661 0.41372855 0.3055600 5.396204e-01
24 0.47942584 0.71890752 0.4814340 3.924752e-01
25 100.68191347 100.11710451 100.0443692 1.002326e+02
Why observation $5^th$ is 200+ and no outlier in $x4$???
r statistics outlier
r statistics outlier
edited Oct 6 '18 at 3:21
Angel
asked Oct 5 '18 at 9:11
AngelAngel
265
265
bumped to the homepage by Community♦ 36 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 36 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
$begingroup$
Something likex[seq(5,25,5)]=x[seq(5,25,5)]+100?
$endgroup$
– user2974951
Oct 5 '18 at 10:22
$begingroup$
@user2974951 Kindly see my edit.
$endgroup$
– Angel
Oct 6 '18 at 3:23
add a comment |
1
$begingroup$
Something likex[seq(5,25,5)]=x[seq(5,25,5)]+100?
$endgroup$
– user2974951
Oct 5 '18 at 10:22
$begingroup$
@user2974951 Kindly see my edit.
$endgroup$
– Angel
Oct 6 '18 at 3:23
1
1
$begingroup$
Something like
x[seq(5,25,5)]=x[seq(5,25,5)]+100?$endgroup$
– user2974951
Oct 5 '18 at 10:22
$begingroup$
Something like
x[seq(5,25,5)]=x[seq(5,25,5)]+100?$endgroup$
– user2974951
Oct 5 '18 at 10:22
$begingroup$
@user2974951 Kindly see my edit.
$endgroup$
– Angel
Oct 6 '18 at 3:23
$begingroup$
@user2974951 Kindly see my edit.
$endgroup$
– Angel
Oct 6 '18 at 3:23
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
You have a data frame with 4 columns, each columns has 25 rows. You want to replace every 5th element with an outlying value (the mean of the column).
apply(x,2,function(i)
i[seq(5,25,5)]=i[seq(5,25,5)]+mean(i)
)
$endgroup$
$begingroup$
For my further work, i have to increase my $n$ and replacement is till 25th observation, but in that replacement is done till end. How to control this?
$endgroup$
– Angel
Oct 24 '18 at 3:49
$begingroup$
Your code is different from mine, have you tried using my code to get the desired result? It should work. As for increasing $n$, all you have to do is change $25$ to the new value, or for ex.nrow(x).
$endgroup$
– user2974951
Oct 24 '18 at 6:05
$begingroup$
For Increasing n, suppose $n=50$ only want to change in 1st 25 values...
$endgroup$
– Angel
Oct 26 '18 at 4:36
$begingroup$
OK then it's the same code.
$endgroup$
– user2974951
Oct 26 '18 at 5:00
add a comment |
$begingroup$
You added 100 twice. And Nx4 is the same -- except that it's in scientific notations.
Nx1 = x1
Nx1[seq(5, 25, 5)] = mean(x1) + 100
will do.
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2fdatascience.stackexchange.com%2fquestions%2f39223%2freplace-values-in-vector-on-specific-place-in-r%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
You have a data frame with 4 columns, each columns has 25 rows. You want to replace every 5th element with an outlying value (the mean of the column).
apply(x,2,function(i)
i[seq(5,25,5)]=i[seq(5,25,5)]+mean(i)
)
$endgroup$
$begingroup$
For my further work, i have to increase my $n$ and replacement is till 25th observation, but in that replacement is done till end. How to control this?
$endgroup$
– Angel
Oct 24 '18 at 3:49
$begingroup$
Your code is different from mine, have you tried using my code to get the desired result? It should work. As for increasing $n$, all you have to do is change $25$ to the new value, or for ex.nrow(x).
$endgroup$
– user2974951
Oct 24 '18 at 6:05
$begingroup$
For Increasing n, suppose $n=50$ only want to change in 1st 25 values...
$endgroup$
– Angel
Oct 26 '18 at 4:36
$begingroup$
OK then it's the same code.
$endgroup$
– user2974951
Oct 26 '18 at 5:00
add a comment |
$begingroup$
You have a data frame with 4 columns, each columns has 25 rows. You want to replace every 5th element with an outlying value (the mean of the column).
apply(x,2,function(i)
i[seq(5,25,5)]=i[seq(5,25,5)]+mean(i)
)
$endgroup$
$begingroup$
For my further work, i have to increase my $n$ and replacement is till 25th observation, but in that replacement is done till end. How to control this?
$endgroup$
– Angel
Oct 24 '18 at 3:49
$begingroup$
Your code is different from mine, have you tried using my code to get the desired result? It should work. As for increasing $n$, all you have to do is change $25$ to the new value, or for ex.nrow(x).
$endgroup$
– user2974951
Oct 24 '18 at 6:05
$begingroup$
For Increasing n, suppose $n=50$ only want to change in 1st 25 values...
$endgroup$
– Angel
Oct 26 '18 at 4:36
$begingroup$
OK then it's the same code.
$endgroup$
– user2974951
Oct 26 '18 at 5:00
add a comment |
$begingroup$
You have a data frame with 4 columns, each columns has 25 rows. You want to replace every 5th element with an outlying value (the mean of the column).
apply(x,2,function(i)
i[seq(5,25,5)]=i[seq(5,25,5)]+mean(i)
)
$endgroup$
You have a data frame with 4 columns, each columns has 25 rows. You want to replace every 5th element with an outlying value (the mean of the column).
apply(x,2,function(i)
i[seq(5,25,5)]=i[seq(5,25,5)]+mean(i)
)
answered Oct 6 '18 at 7:28
user2974951user2974951
2355
2355
$begingroup$
For my further work, i have to increase my $n$ and replacement is till 25th observation, but in that replacement is done till end. How to control this?
$endgroup$
– Angel
Oct 24 '18 at 3:49
$begingroup$
Your code is different from mine, have you tried using my code to get the desired result? It should work. As for increasing $n$, all you have to do is change $25$ to the new value, or for ex.nrow(x).
$endgroup$
– user2974951
Oct 24 '18 at 6:05
$begingroup$
For Increasing n, suppose $n=50$ only want to change in 1st 25 values...
$endgroup$
– Angel
Oct 26 '18 at 4:36
$begingroup$
OK then it's the same code.
$endgroup$
– user2974951
Oct 26 '18 at 5:00
add a comment |
$begingroup$
For my further work, i have to increase my $n$ and replacement is till 25th observation, but in that replacement is done till end. How to control this?
$endgroup$
– Angel
Oct 24 '18 at 3:49
$begingroup$
Your code is different from mine, have you tried using my code to get the desired result? It should work. As for increasing $n$, all you have to do is change $25$ to the new value, or for ex.nrow(x).
$endgroup$
– user2974951
Oct 24 '18 at 6:05
$begingroup$
For Increasing n, suppose $n=50$ only want to change in 1st 25 values...
$endgroup$
– Angel
Oct 26 '18 at 4:36
$begingroup$
OK then it's the same code.
$endgroup$
– user2974951
Oct 26 '18 at 5:00
$begingroup$
For my further work, i have to increase my $n$ and replacement is till 25th observation, but in that replacement is done till end. How to control this?
$endgroup$
– Angel
Oct 24 '18 at 3:49
$begingroup$
For my further work, i have to increase my $n$ and replacement is till 25th observation, but in that replacement is done till end. How to control this?
$endgroup$
– Angel
Oct 24 '18 at 3:49
$begingroup$
Your code is different from mine, have you tried using my code to get the desired result? It should work. As for increasing $n$, all you have to do is change $25$ to the new value, or for ex.
nrow(x).$endgroup$
– user2974951
Oct 24 '18 at 6:05
$begingroup$
Your code is different from mine, have you tried using my code to get the desired result? It should work. As for increasing $n$, all you have to do is change $25$ to the new value, or for ex.
nrow(x).$endgroup$
– user2974951
Oct 24 '18 at 6:05
$begingroup$
For Increasing n, suppose $n=50$ only want to change in 1st 25 values...
$endgroup$
– Angel
Oct 26 '18 at 4:36
$begingroup$
For Increasing n, suppose $n=50$ only want to change in 1st 25 values...
$endgroup$
– Angel
Oct 26 '18 at 4:36
$begingroup$
OK then it's the same code.
$endgroup$
– user2974951
Oct 26 '18 at 5:00
$begingroup$
OK then it's the same code.
$endgroup$
– user2974951
Oct 26 '18 at 5:00
add a comment |
$begingroup$
You added 100 twice. And Nx4 is the same -- except that it's in scientific notations.
Nx1 = x1
Nx1[seq(5, 25, 5)] = mean(x1) + 100
will do.
$endgroup$
add a comment |
$begingroup$
You added 100 twice. And Nx4 is the same -- except that it's in scientific notations.
Nx1 = x1
Nx1[seq(5, 25, 5)] = mean(x1) + 100
will do.
$endgroup$
add a comment |
$begingroup$
You added 100 twice. And Nx4 is the same -- except that it's in scientific notations.
Nx1 = x1
Nx1[seq(5, 25, 5)] = mean(x1) + 100
will do.
$endgroup$
You added 100 twice. And Nx4 is the same -- except that it's in scientific notations.
Nx1 = x1
Nx1[seq(5, 25, 5)] = mean(x1) + 100
will do.
answered Oct 15 '18 at 17:02
bellmaneqnbellmaneqn
191
191
add a comment |
add a comment |
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
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%2fdatascience.stackexchange.com%2fquestions%2f39223%2freplace-values-in-vector-on-specific-place-in-r%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
$begingroup$
Something like
x[seq(5,25,5)]=x[seq(5,25,5)]+100?$endgroup$
– user2974951
Oct 5 '18 at 10:22
$begingroup$
@user2974951 Kindly see my edit.
$endgroup$
– Angel
Oct 6 '18 at 3:23