Extract the values from the dataframes created in a loop for further analysis (I am not sure, how to sum up the question in one line) The Next CEO of Stack OverflowHow to make a great R reproducible exampleHow do I replace NA values with zeros in an R dataframe?Use a list of values to select rows from a pandas dataframeHow can I replace all the NaN values with Zero's in a column of a pandas dataframeHow to drop rows of Pandas DataFrame whose value in certain columns is NaNHow to get a value from a cell of a dataframe?Select rows from a DataFrame based on values in a column in pandasHow to count the NaN values in a column in pandas DataFrameHow to check if any value is NaN in a Pandas DataFrameTransforming panal dataForecast pop in the gapminder dataset and extract the predicted value in the same format as gapminder
What does "Its cash flow is deeply negative" mean?
Is HostGator storing my password in plaintext?
If the heap is initialized for security, then why is the stack uninitialized?
Inappropriate reference requests from Journal reviewers
What is the purpose of the Evocation wizard's Potent Cantrip feature?
MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs
What can we do to stop prior company from asking us questions?
How do I get the green key off the shelf in the Dobby level of Lego Harry Potter 2?
Anatomically Correct Mesopelagic Aves
How to Reset Passwords on Multiple Websites Easily?
Trouble understanding the speech of overseas colleagues
Whats the best way to handle refactoring a big file?
Can a caster that cast Polymorph on themselves stop concentrating at any point even if their Int is low?
Why is there a PLL in CPU?
Customer Requests (Sometimes) Drive Me Bonkers!
How to be diplomatic in refusing to write code that breaches the privacy of our users
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
Why did we only see the N-1 starfighters in one film?
Can a single photon have an energy density?
How can I quit an app using Terminal?
Science fiction (dystopian) short story set after WWIII
Unreliable Magic - Is it worth it?
Is the concept of a "numerable" fiber bundle really useful or an empty generalization?
Can the Reverse Gravity spell affect the Meteor Swarm spell?
Extract the values from the dataframes created in a loop for further analysis (I am not sure, how to sum up the question in one line)
The Next CEO of Stack OverflowHow to make a great R reproducible exampleHow do I replace NA values with zeros in an R dataframe?Use a list of values to select rows from a pandas dataframeHow can I replace all the NaN values with Zero's in a column of a pandas dataframeHow to drop rows of Pandas DataFrame whose value in certain columns is NaNHow to get a value from a cell of a dataframe?Select rows from a DataFrame based on values in a column in pandasHow to count the NaN values in a column in pandas DataFrameHow to check if any value is NaN in a Pandas DataFrameTransforming panal dataForecast pop in the gapminder dataset and extract the predicted value in the same format as gapminder
My raw dataset has multiple product Id, monthly sales and corresponding date arranged in a matrix format. I wish to create individual dataframes for each product_id along with the sales value and dates. For this, I am using a for loop.
base is the base dataset.
x is the variable that contains the unique product_id and the corresponding no of observation points.
for(i in 1:nrow(x))
n <- paste("df", x$vars[i], sep = "")
assign(n, base[base[,1] == x$vars[i],])
print(n)
This is a part of the output:
[1] "df25"
[1] "df28"
[1] "df35"
[1] "df37"
[1] "df39"
So all the dataframe names are saved in n. This, I think is a string vector.
When I write df25 outside the loop, I get the dataframe I want:
> df25
# A tibble: 49 x 3
ID date Sales
<dbl> <date> <dbl>
1 25 2014-01-01 0
2 25 2014-02-01 0
3 25 2014-03-01 0
4 25 2014-04-01 0
5 25 2014-05-01 0
6 25 2014-06-01 0
7 25 2014-07-01 0
8 25 2014-08-01 0
9 25 2014-09-01 0
10 25 2014-10-01 0
# ... with 39 more rows
Now, I want to use each of these dataframes seperately to perform a forecast analysis. For doing this, I need to get to the values in individual dataframes. This is what I have tried for the same:
for(i in 1:4) print(paste0("df", x$vars[i]))
[1] "df2"
[1] "df3"
[1] "df5"
[1] "df14"
But I am unable to refer to individual dataframes.
I am looking for help on how can I get access to the dataframes with their values for further analysis? Since there are more than 200 products, I am looking for some function which deals with all the dataframes.
First, I wish to convert it to a TS
, using year
and month
values from the date
variable and then use ets
or forecast,
etc.
SAMPLE DATASET:
set.seed(354)
df <- data.frame(Product_Id = rep(1:10, each = 50),
Date = seq(from = as.Date("2014/1/1"), to = as.Date("2018/2/1") , by = "month"),
Sales = rnorm(100, mean = 50, sd= 20))
df <- df[-c(251:256, 301:312) ,]
As always, any suggestion would be highly appreciated.
r dataframe forecasting forecast
add a comment |
My raw dataset has multiple product Id, monthly sales and corresponding date arranged in a matrix format. I wish to create individual dataframes for each product_id along with the sales value and dates. For this, I am using a for loop.
base is the base dataset.
x is the variable that contains the unique product_id and the corresponding no of observation points.
for(i in 1:nrow(x))
n <- paste("df", x$vars[i], sep = "")
assign(n, base[base[,1] == x$vars[i],])
print(n)
This is a part of the output:
[1] "df25"
[1] "df28"
[1] "df35"
[1] "df37"
[1] "df39"
So all the dataframe names are saved in n. This, I think is a string vector.
When I write df25 outside the loop, I get the dataframe I want:
> df25
# A tibble: 49 x 3
ID date Sales
<dbl> <date> <dbl>
1 25 2014-01-01 0
2 25 2014-02-01 0
3 25 2014-03-01 0
4 25 2014-04-01 0
5 25 2014-05-01 0
6 25 2014-06-01 0
7 25 2014-07-01 0
8 25 2014-08-01 0
9 25 2014-09-01 0
10 25 2014-10-01 0
# ... with 39 more rows
Now, I want to use each of these dataframes seperately to perform a forecast analysis. For doing this, I need to get to the values in individual dataframes. This is what I have tried for the same:
for(i in 1:4) print(paste0("df", x$vars[i]))
[1] "df2"
[1] "df3"
[1] "df5"
[1] "df14"
But I am unable to refer to individual dataframes.
I am looking for help on how can I get access to the dataframes with their values for further analysis? Since there are more than 200 products, I am looking for some function which deals with all the dataframes.
First, I wish to convert it to a TS
, using year
and month
values from the date
variable and then use ets
or forecast,
etc.
SAMPLE DATASET:
set.seed(354)
df <- data.frame(Product_Id = rep(1:10, each = 50),
Date = seq(from = as.Date("2014/1/1"), to = as.Date("2018/2/1") , by = "month"),
Sales = rnorm(100, mean = 50, sd= 20))
df <- df[-c(251:256, 301:312) ,]
As always, any suggestion would be highly appreciated.
r dataframe forecasting forecast
1
side note: usually it is better practice not to assing new variables in a for loop, but use lists instead.
– Wimpel
Mar 7 at 14:10
I agree with @Wimpel. consider using lists and the purrr package. that should make this a lot easier from the start
– Bernd Konfuzius
Mar 7 at 14:31
Hey, can you please help me with some example? Are you suggesting to totally abandon for loop (I am quite new to R)?
– user10579790
Mar 7 at 14:38
@user10579790 please provide some sample-data, usingdput()
. Further: read this: stackoverflow.com/questions/5963269/…
– Wimpel
Mar 7 at 15:00
Hey, I am adding a sample dataset as an edit to the question.
– user10579790
Mar 8 at 10:41
add a comment |
My raw dataset has multiple product Id, monthly sales and corresponding date arranged in a matrix format. I wish to create individual dataframes for each product_id along with the sales value and dates. For this, I am using a for loop.
base is the base dataset.
x is the variable that contains the unique product_id and the corresponding no of observation points.
for(i in 1:nrow(x))
n <- paste("df", x$vars[i], sep = "")
assign(n, base[base[,1] == x$vars[i],])
print(n)
This is a part of the output:
[1] "df25"
[1] "df28"
[1] "df35"
[1] "df37"
[1] "df39"
So all the dataframe names are saved in n. This, I think is a string vector.
When I write df25 outside the loop, I get the dataframe I want:
> df25
# A tibble: 49 x 3
ID date Sales
<dbl> <date> <dbl>
1 25 2014-01-01 0
2 25 2014-02-01 0
3 25 2014-03-01 0
4 25 2014-04-01 0
5 25 2014-05-01 0
6 25 2014-06-01 0
7 25 2014-07-01 0
8 25 2014-08-01 0
9 25 2014-09-01 0
10 25 2014-10-01 0
# ... with 39 more rows
Now, I want to use each of these dataframes seperately to perform a forecast analysis. For doing this, I need to get to the values in individual dataframes. This is what I have tried for the same:
for(i in 1:4) print(paste0("df", x$vars[i]))
[1] "df2"
[1] "df3"
[1] "df5"
[1] "df14"
But I am unable to refer to individual dataframes.
I am looking for help on how can I get access to the dataframes with their values for further analysis? Since there are more than 200 products, I am looking for some function which deals with all the dataframes.
First, I wish to convert it to a TS
, using year
and month
values from the date
variable and then use ets
or forecast,
etc.
SAMPLE DATASET:
set.seed(354)
df <- data.frame(Product_Id = rep(1:10, each = 50),
Date = seq(from = as.Date("2014/1/1"), to = as.Date("2018/2/1") , by = "month"),
Sales = rnorm(100, mean = 50, sd= 20))
df <- df[-c(251:256, 301:312) ,]
As always, any suggestion would be highly appreciated.
r dataframe forecasting forecast
My raw dataset has multiple product Id, monthly sales and corresponding date arranged in a matrix format. I wish to create individual dataframes for each product_id along with the sales value and dates. For this, I am using a for loop.
base is the base dataset.
x is the variable that contains the unique product_id and the corresponding no of observation points.
for(i in 1:nrow(x))
n <- paste("df", x$vars[i], sep = "")
assign(n, base[base[,1] == x$vars[i],])
print(n)
This is a part of the output:
[1] "df25"
[1] "df28"
[1] "df35"
[1] "df37"
[1] "df39"
So all the dataframe names are saved in n. This, I think is a string vector.
When I write df25 outside the loop, I get the dataframe I want:
> df25
# A tibble: 49 x 3
ID date Sales
<dbl> <date> <dbl>
1 25 2014-01-01 0
2 25 2014-02-01 0
3 25 2014-03-01 0
4 25 2014-04-01 0
5 25 2014-05-01 0
6 25 2014-06-01 0
7 25 2014-07-01 0
8 25 2014-08-01 0
9 25 2014-09-01 0
10 25 2014-10-01 0
# ... with 39 more rows
Now, I want to use each of these dataframes seperately to perform a forecast analysis. For doing this, I need to get to the values in individual dataframes. This is what I have tried for the same:
for(i in 1:4) print(paste0("df", x$vars[i]))
[1] "df2"
[1] "df3"
[1] "df5"
[1] "df14"
But I am unable to refer to individual dataframes.
I am looking for help on how can I get access to the dataframes with their values for further analysis? Since there are more than 200 products, I am looking for some function which deals with all the dataframes.
First, I wish to convert it to a TS
, using year
and month
values from the date
variable and then use ets
or forecast,
etc.
SAMPLE DATASET:
set.seed(354)
df <- data.frame(Product_Id = rep(1:10, each = 50),
Date = seq(from = as.Date("2014/1/1"), to = as.Date("2018/2/1") , by = "month"),
Sales = rnorm(100, mean = 50, sd= 20))
df <- df[-c(251:256, 301:312) ,]
As always, any suggestion would be highly appreciated.
r dataframe forecasting forecast
r dataframe forecasting forecast
edited Mar 8 at 10:42
user10579790
asked Mar 7 at 14:08
user10579790user10579790
819
819
1
side note: usually it is better practice not to assing new variables in a for loop, but use lists instead.
– Wimpel
Mar 7 at 14:10
I agree with @Wimpel. consider using lists and the purrr package. that should make this a lot easier from the start
– Bernd Konfuzius
Mar 7 at 14:31
Hey, can you please help me with some example? Are you suggesting to totally abandon for loop (I am quite new to R)?
– user10579790
Mar 7 at 14:38
@user10579790 please provide some sample-data, usingdput()
. Further: read this: stackoverflow.com/questions/5963269/…
– Wimpel
Mar 7 at 15:00
Hey, I am adding a sample dataset as an edit to the question.
– user10579790
Mar 8 at 10:41
add a comment |
1
side note: usually it is better practice not to assing new variables in a for loop, but use lists instead.
– Wimpel
Mar 7 at 14:10
I agree with @Wimpel. consider using lists and the purrr package. that should make this a lot easier from the start
– Bernd Konfuzius
Mar 7 at 14:31
Hey, can you please help me with some example? Are you suggesting to totally abandon for loop (I am quite new to R)?
– user10579790
Mar 7 at 14:38
@user10579790 please provide some sample-data, usingdput()
. Further: read this: stackoverflow.com/questions/5963269/…
– Wimpel
Mar 7 at 15:00
Hey, I am adding a sample dataset as an edit to the question.
– user10579790
Mar 8 at 10:41
1
1
side note: usually it is better practice not to assing new variables in a for loop, but use lists instead.
– Wimpel
Mar 7 at 14:10
side note: usually it is better practice not to assing new variables in a for loop, but use lists instead.
– Wimpel
Mar 7 at 14:10
I agree with @Wimpel. consider using lists and the purrr package. that should make this a lot easier from the start
– Bernd Konfuzius
Mar 7 at 14:31
I agree with @Wimpel. consider using lists and the purrr package. that should make this a lot easier from the start
– Bernd Konfuzius
Mar 7 at 14:31
Hey, can you please help me with some example? Are you suggesting to totally abandon for loop (I am quite new to R)?
– user10579790
Mar 7 at 14:38
Hey, can you please help me with some example? Are you suggesting to totally abandon for loop (I am quite new to R)?
– user10579790
Mar 7 at 14:38
@user10579790 please provide some sample-data, using
dput()
. Further: read this: stackoverflow.com/questions/5963269/…– Wimpel
Mar 7 at 15:00
@user10579790 please provide some sample-data, using
dput()
. Further: read this: stackoverflow.com/questions/5963269/…– Wimpel
Mar 7 at 15:00
Hey, I am adding a sample dataset as an edit to the question.
– user10579790
Mar 8 at 10:41
Hey, I am adding a sample dataset as an edit to the question.
– user10579790
Mar 8 at 10:41
add a comment |
1 Answer
1
active
oldest
votes
I think this is one way to get an access to the individual dataframes. If there is a better method, please let me know:
(Var <- get(paste0("df",x$vars[i])))
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f55045765%2fextract-the-values-from-the-dataframes-created-in-a-loop-for-further-analysis-i%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think this is one way to get an access to the individual dataframes. If there is a better method, please let me know:
(Var <- get(paste0("df",x$vars[i])))
add a comment |
I think this is one way to get an access to the individual dataframes. If there is a better method, please let me know:
(Var <- get(paste0("df",x$vars[i])))
add a comment |
I think this is one way to get an access to the individual dataframes. If there is a better method, please let me know:
(Var <- get(paste0("df",x$vars[i])))
I think this is one way to get an access to the individual dataframes. If there is a better method, please let me know:
(Var <- get(paste0("df",x$vars[i])))
answered Mar 8 at 13:46
user10579790user10579790
819
819
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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.
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%2fstackoverflow.com%2fquestions%2f55045765%2fextract-the-values-from-the-dataframes-created-in-a-loop-for-further-analysis-i%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
side note: usually it is better practice not to assing new variables in a for loop, but use lists instead.
– Wimpel
Mar 7 at 14:10
I agree with @Wimpel. consider using lists and the purrr package. that should make this a lot easier from the start
– Bernd Konfuzius
Mar 7 at 14:31
Hey, can you please help me with some example? Are you suggesting to totally abandon for loop (I am quite new to R)?
– user10579790
Mar 7 at 14:38
@user10579790 please provide some sample-data, using
dput()
. Further: read this: stackoverflow.com/questions/5963269/…– Wimpel
Mar 7 at 15:00
Hey, I am adding a sample dataset as an edit to the question.
– user10579790
Mar 8 at 10:41