I have an empty dataframe which I want to fill using another dataframeRecalculate each point in dataframe with lapply/sapplyCreating an empty Pandas DataFrame, then filling it?How to check whether a pandas DataFrame is empty?R: Creating a data frame from list with missing values.Fill pandas dataframe with specific values from jsonHow to increment values in a matrix using 3 for loops in RRemove columns from dataframe where ALL values are NA, NULL or emptyHow to subset variables which have NA in the values?r - Filtering by Rank in a df with with NAs - Not workingWhat is wrong with my pattern matching and replacement function
Enumerate Derangements
CRT Oscilloscope - part of the plot is missing
Is it cheaper to drop cargo than to land it?
What is the most remote airport from the center of the city it supposedly serves?
Sed Usage to update GRUB file
Is Cola "probably the best-known" Latin word in the world? If not, which might it be?
What happens to matryoshka Mordenkainen's Magnificent Mansions?
Returning the outputs of a nested structure
Is it possible to set that path of the scp command to use by OpenSSH sshd daemon?
What are the differences between credential stuffing and password spraying?
Pressure to defend the relevance of one's area of mathematics
Reconstruct a matrix from its traces
Should my Json storage handle exceptions?
I caught several of my students plagiarizing. Could it be my fault as a teacher?
How do I tell my manager that his code review comment is wrong?
LightGBM results differently depending on the order of the data
Casual versus formal jacket
To customize a predefined symbol with different colors only with pdfLaTeX
when are two topological spaces homeomorphic?
Would glacier 'trees' be plausible?
Which industry am I working in? Software development or financial services?
Why do computer-science majors learn calculus?
How could a planet have most of its water in the atmosphere?
Do I have to make someone coauthor if he/she solves a problem in StackExchange, asked by myself, which is later used in my paper?
I have an empty dataframe which I want to fill using another dataframe
Recalculate each point in dataframe with lapply/sapplyCreating an empty Pandas DataFrame, then filling it?How to check whether a pandas DataFrame is empty?R: Creating a data frame from list with missing values.Fill pandas dataframe with specific values from jsonHow to increment values in a matrix using 3 for loops in RRemove columns from dataframe where ALL values are NA, NULL or emptyHow to subset variables which have NA in the values?r - Filtering by Rank in a df with with NAs - Not workingWhat is wrong with my pattern matching and replacement function
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have an empty dataframe which is my template
temp <- data.frame(matrix(ncol=3))
colnames(temp) <- c("variable", "group", "bin")
And another dataframe which has the details of these:
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
I want the variable name to be "group_abc", and group to have values of group_abc and bin to have values of bin_abc.
When I was trying to use the values from the dataframe, it gives me an error saying: Error in$<-.data.frame(tmp, group, value = c("0-699", "700-750", :
replacement has 6 rows, data has 1
r dataframe multiple-columns is-empty
add a comment |
I have an empty dataframe which is my template
temp <- data.frame(matrix(ncol=3))
colnames(temp) <- c("variable", "group", "bin")
And another dataframe which has the details of these:
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
I want the variable name to be "group_abc", and group to have values of group_abc and bin to have values of bin_abc.
When I was trying to use the values from the dataframe, it gives me an error saying: Error in$<-.data.frame(tmp, group, value = c("0-699", "700-750", :
replacement has 6 rows, data has 1
r dataframe multiple-columns is-empty
add a comment |
I have an empty dataframe which is my template
temp <- data.frame(matrix(ncol=3))
colnames(temp) <- c("variable", "group", "bin")
And another dataframe which has the details of these:
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
I want the variable name to be "group_abc", and group to have values of group_abc and bin to have values of bin_abc.
When I was trying to use the values from the dataframe, it gives me an error saying: Error in$<-.data.frame(tmp, group, value = c("0-699", "700-750", :
replacement has 6 rows, data has 1
r dataframe multiple-columns is-empty
I have an empty dataframe which is my template
temp <- data.frame(matrix(ncol=3))
colnames(temp) <- c("variable", "group", "bin")
And another dataframe which has the details of these:
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
I want the variable name to be "group_abc", and group to have values of group_abc and bin to have values of bin_abc.
When I was trying to use the values from the dataframe, it gives me an error saying: Error in$<-.data.frame(tmp, group, value = c("0-699", "700-750", :
replacement has 6 rows, data has 1
r dataframe multiple-columns is-empty
r dataframe multiple-columns is-empty
asked Mar 22 at 21:05
Bruce WayneBruce Wayne
11212
11212
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Just assign (value of) the existing dataframe to the new name but change the column names which can be done in one easy step:
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
temp <- setNames( info, c("group", "bin"))
> temp
group bin
1 1 0-700
2 2 700-750
3 2 750-800
4 3 800-850
5 3 850-900
6 3 900-950
If you had wanted only a portion of the existing dataframe to get duplicated, you could have selected either rows or columns or both using "[" on the info argument with the setNames call.
add a comment |
You could resolve this by setting up the temp dataframe to have the correct number of rows as well as the correct number of columns when being initialized.
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
temp <- data.frame(matrix(ncol=3, nrow = nrow(info)))
colnames(temp) <- c("variable", "group", "bin")
temp$group <- info$group_abc
temp$bin <- info$bin_abc
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%2f55307757%2fi-have-an-empty-dataframe-which-i-want-to-fill-using-another-dataframe%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
Just assign (value of) the existing dataframe to the new name but change the column names which can be done in one easy step:
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
temp <- setNames( info, c("group", "bin"))
> temp
group bin
1 1 0-700
2 2 700-750
3 2 750-800
4 3 800-850
5 3 850-900
6 3 900-950
If you had wanted only a portion of the existing dataframe to get duplicated, you could have selected either rows or columns or both using "[" on the info argument with the setNames call.
add a comment |
Just assign (value of) the existing dataframe to the new name but change the column names which can be done in one easy step:
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
temp <- setNames( info, c("group", "bin"))
> temp
group bin
1 1 0-700
2 2 700-750
3 2 750-800
4 3 800-850
5 3 850-900
6 3 900-950
If you had wanted only a portion of the existing dataframe to get duplicated, you could have selected either rows or columns or both using "[" on the info argument with the setNames call.
add a comment |
Just assign (value of) the existing dataframe to the new name but change the column names which can be done in one easy step:
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
temp <- setNames( info, c("group", "bin"))
> temp
group bin
1 1 0-700
2 2 700-750
3 2 750-800
4 3 800-850
5 3 850-900
6 3 900-950
If you had wanted only a portion of the existing dataframe to get duplicated, you could have selected either rows or columns or both using "[" on the info argument with the setNames call.
Just assign (value of) the existing dataframe to the new name but change the column names which can be done in one easy step:
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
temp <- setNames( info, c("group", "bin"))
> temp
group bin
1 1 0-700
2 2 700-750
3 2 750-800
4 3 800-850
5 3 850-900
6 3 900-950
If you had wanted only a portion of the existing dataframe to get duplicated, you could have selected either rows or columns or both using "[" on the info argument with the setNames call.
answered Mar 22 at 22:46
42-42-
217k15270406
217k15270406
add a comment |
add a comment |
You could resolve this by setting up the temp dataframe to have the correct number of rows as well as the correct number of columns when being initialized.
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
temp <- data.frame(matrix(ncol=3, nrow = nrow(info)))
colnames(temp) <- c("variable", "group", "bin")
temp$group <- info$group_abc
temp$bin <- info$bin_abc
add a comment |
You could resolve this by setting up the temp dataframe to have the correct number of rows as well as the correct number of columns when being initialized.
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
temp <- data.frame(matrix(ncol=3, nrow = nrow(info)))
colnames(temp) <- c("variable", "group", "bin")
temp$group <- info$group_abc
temp$bin <- info$bin_abc
add a comment |
You could resolve this by setting up the temp dataframe to have the correct number of rows as well as the correct number of columns when being initialized.
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
temp <- data.frame(matrix(ncol=3, nrow = nrow(info)))
colnames(temp) <- c("variable", "group", "bin")
temp$group <- info$group_abc
temp$bin <- info$bin_abc
You could resolve this by setting up the temp dataframe to have the correct number of rows as well as the correct number of columns when being initialized.
info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
temp <- data.frame(matrix(ncol=3, nrow = nrow(info)))
colnames(temp) <- c("variable", "group", "bin")
temp$group <- info$group_abc
temp$bin <- info$bin_abc
answered Mar 22 at 21:13
Emily KotheEmily Kothe
461216
461216
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%2f55307757%2fi-have-an-empty-dataframe-which-i-want-to-fill-using-another-dataframe%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