How do I merge objects with the same character within a column?How to sort a dataframe by multiple column(s)How to join (merge) data frames (inner, outer, left, right)How to sum a variable by groupGrouping functions (tapply, by, aggregate) and the *apply familyTools for making latex tables in RAdd new row to dataframe, at specific row-index, not appended?R- format a data.frame into another 'combined' data.frame based on common values within a column dependent across different columnsdata.table vs dplyr: can one do something well the other can't or does poorly?Merging columns with column names from listHow to display individual objects in a column
Has there ever been an airliner design involving reducing generator load by installing solar panels?
Arrow those variables!
Perform and show arithmetic with LuaLaTeX
How old can references or sources in a thesis be?
Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?
Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?
RSA: Danger of using p to create q
Could an aircraft fly or hover using only jets of compressed air?
What's the output of a record needle playing an out-of-speed record
Can I ask the recruiters in my resume to put the reason why I am rejected?
Why do I get two different answers for this counting problem?
Convert two switches to a dual stack, and add outlet - possible here?
Can a Cauchy sequence converge for one metric while not converging for another?
I'm flying to France today and my passport expires in less than 2 months
What is the word for reserving something for yourself before others do?
Do infinite dimensional systems make sense?
Do I have a twin with permutated remainders?
How much of data wrangling is a data scientist's job?
Add text to same line using sed
Is it unprofessional to ask if a job posting on GlassDoor is real?
Does detail obscure or enhance action?
Revoked SSL certificate
How does quantile regression compare to logistic regression with the variable split at the quantile?
Is it possible to run Internet Explorer on OS X El Capitan?
How do I merge objects with the same character within a column?
How to sort a dataframe by multiple column(s)How to join (merge) data frames (inner, outer, left, right)How to sum a variable by groupGrouping functions (tapply, by, aggregate) and the *apply familyTools for making latex tables in RAdd new row to dataframe, at specific row-index, not appended?R- format a data.frame into another 'combined' data.frame based on common values within a column dependent across different columnsdata.table vs dplyr: can one do something well the other can't or does poorly?Merging columns with column names from listHow to display individual objects in a column
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Let's say I have a DF of just 1 column "Genre"
and within that Genre there are "Horror", "Romance", "Fiction" etc.
Genre
Horror
Horror
Romance
Fiction
Romance
How do I code so that I can combine the "Horror" objects to just one?
So basically, I want the table to show
Genre
Horror
Romance
Fiction
Thanks in advance
r
add a comment |
Let's say I have a DF of just 1 column "Genre"
and within that Genre there are "Horror", "Romance", "Fiction" etc.
Genre
Horror
Horror
Romance
Fiction
Romance
How do I code so that I can combine the "Horror" objects to just one?
So basically, I want the table to show
Genre
Horror
Romance
Fiction
Thanks in advance
r
2
unique(DF$Genre)
– G5W
Mar 9 at 1:01
Let me revise my question sorry about that Let's say I have a DF of just 2 columns "Genre" and "score" within that Genre there are "Horror", "Romance", "Fiction" etc.Genre Score Horror 4 Horror 6 Romance 7 Fiction 3 Romance 10How do I code so that I can combine the "Horror" objects to just one? So basically, I want the table to showGenre Score Horror mean(score) Romance mean(score) Fiction mean(score)
– Thom JAckson
Mar 9 at 1:11
add a comment |
Let's say I have a DF of just 1 column "Genre"
and within that Genre there are "Horror", "Romance", "Fiction" etc.
Genre
Horror
Horror
Romance
Fiction
Romance
How do I code so that I can combine the "Horror" objects to just one?
So basically, I want the table to show
Genre
Horror
Romance
Fiction
Thanks in advance
r
Let's say I have a DF of just 1 column "Genre"
and within that Genre there are "Horror", "Romance", "Fiction" etc.
Genre
Horror
Horror
Romance
Fiction
Romance
How do I code so that I can combine the "Horror" objects to just one?
So basically, I want the table to show
Genre
Horror
Romance
Fiction
Thanks in advance
r
r
edited Mar 9 at 5:46
NelsonGon
3,6044834
3,6044834
asked Mar 9 at 0:57
Thom JAcksonThom JAckson
1
1
2
unique(DF$Genre)
– G5W
Mar 9 at 1:01
Let me revise my question sorry about that Let's say I have a DF of just 2 columns "Genre" and "score" within that Genre there are "Horror", "Romance", "Fiction" etc.Genre Score Horror 4 Horror 6 Romance 7 Fiction 3 Romance 10How do I code so that I can combine the "Horror" objects to just one? So basically, I want the table to showGenre Score Horror mean(score) Romance mean(score) Fiction mean(score)
– Thom JAckson
Mar 9 at 1:11
add a comment |
2
unique(DF$Genre)
– G5W
Mar 9 at 1:01
Let me revise my question sorry about that Let's say I have a DF of just 2 columns "Genre" and "score" within that Genre there are "Horror", "Romance", "Fiction" etc.Genre Score Horror 4 Horror 6 Romance 7 Fiction 3 Romance 10How do I code so that I can combine the "Horror" objects to just one? So basically, I want the table to showGenre Score Horror mean(score) Romance mean(score) Fiction mean(score)
– Thom JAckson
Mar 9 at 1:11
2
2
unique(DF$Genre)– G5W
Mar 9 at 1:01
unique(DF$Genre)– G5W
Mar 9 at 1:01
Let me revise my question sorry about that Let's say I have a DF of just 2 columns "Genre" and "score" within that Genre there are "Horror", "Romance", "Fiction" etc.
Genre Score Horror 4 Horror 6 Romance 7 Fiction 3 Romance 10 How do I code so that I can combine the "Horror" objects to just one? So basically, I want the table to show Genre Score Horror mean(score) Romance mean(score) Fiction mean(score) – Thom JAckson
Mar 9 at 1:11
Let me revise my question sorry about that Let's say I have a DF of just 2 columns "Genre" and "score" within that Genre there are "Horror", "Romance", "Fiction" etc.
Genre Score Horror 4 Horror 6 Romance 7 Fiction 3 Romance 10 How do I code so that I can combine the "Horror" objects to just one? So basically, I want the table to show Genre Score Horror mean(score) Romance mean(score) Fiction mean(score) – Thom JAckson
Mar 9 at 1:11
add a comment |
2 Answers
2
active
oldest
votes
unique(DF$Genre)
or
DF %>%
distinct(Genre)
Thanks a lot. If it doesnt trouble you, I want to know how I can make a summary of 2 columns genre and score. For example, "summarise(distinct(genre),mean(score))" doesn't work. The original DF contains the column genre,score.
– Thom JAckson
Mar 9 at 1:15
the distinct function in fact deletes the rest of the column (score)
– Thom JAckson
Mar 9 at 1:24
add a comment |
You can get the table that you are looking for using the aggregate function.
## Your sample data
DF = read.table(text="Genre Score
Horror 4
Horror 6
Romance 7
Fiction 3
Romance 10",
header = TRUE)
Make the table
TAB = aggregate(DF$Score, list(DF$Genre), mean)
names(TAB) = c("Genre", "MeanScore")
TAB
Genre MeanScore
1 Fiction 3.0
2 Horror 5.0
3 Romance 8.5
thank you so much. is there a way to change group.1 and x to another variable?
– Thom JAckson
Mar 9 at 1:32
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%2f55072956%2fhow-do-i-merge-objects-with-the-same-character-within-a-column%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
unique(DF$Genre)
or
DF %>%
distinct(Genre)
Thanks a lot. If it doesnt trouble you, I want to know how I can make a summary of 2 columns genre and score. For example, "summarise(distinct(genre),mean(score))" doesn't work. The original DF contains the column genre,score.
– Thom JAckson
Mar 9 at 1:15
the distinct function in fact deletes the rest of the column (score)
– Thom JAckson
Mar 9 at 1:24
add a comment |
unique(DF$Genre)
or
DF %>%
distinct(Genre)
Thanks a lot. If it doesnt trouble you, I want to know how I can make a summary of 2 columns genre and score. For example, "summarise(distinct(genre),mean(score))" doesn't work. The original DF contains the column genre,score.
– Thom JAckson
Mar 9 at 1:15
the distinct function in fact deletes the rest of the column (score)
– Thom JAckson
Mar 9 at 1:24
add a comment |
unique(DF$Genre)
or
DF %>%
distinct(Genre)
unique(DF$Genre)
or
DF %>%
distinct(Genre)
answered Mar 9 at 1:02
K.J.J.KK.J.J.K
12316
12316
Thanks a lot. If it doesnt trouble you, I want to know how I can make a summary of 2 columns genre and score. For example, "summarise(distinct(genre),mean(score))" doesn't work. The original DF contains the column genre,score.
– Thom JAckson
Mar 9 at 1:15
the distinct function in fact deletes the rest of the column (score)
– Thom JAckson
Mar 9 at 1:24
add a comment |
Thanks a lot. If it doesnt trouble you, I want to know how I can make a summary of 2 columns genre and score. For example, "summarise(distinct(genre),mean(score))" doesn't work. The original DF contains the column genre,score.
– Thom JAckson
Mar 9 at 1:15
the distinct function in fact deletes the rest of the column (score)
– Thom JAckson
Mar 9 at 1:24
Thanks a lot. If it doesnt trouble you, I want to know how I can make a summary of 2 columns genre and score. For example, "summarise(distinct(genre),mean(score))" doesn't work. The original DF contains the column genre,score.
– Thom JAckson
Mar 9 at 1:15
Thanks a lot. If it doesnt trouble you, I want to know how I can make a summary of 2 columns genre and score. For example, "summarise(distinct(genre),mean(score))" doesn't work. The original DF contains the column genre,score.
– Thom JAckson
Mar 9 at 1:15
the distinct function in fact deletes the rest of the column (score)
– Thom JAckson
Mar 9 at 1:24
the distinct function in fact deletes the rest of the column (score)
– Thom JAckson
Mar 9 at 1:24
add a comment |
You can get the table that you are looking for using the aggregate function.
## Your sample data
DF = read.table(text="Genre Score
Horror 4
Horror 6
Romance 7
Fiction 3
Romance 10",
header = TRUE)
Make the table
TAB = aggregate(DF$Score, list(DF$Genre), mean)
names(TAB) = c("Genre", "MeanScore")
TAB
Genre MeanScore
1 Fiction 3.0
2 Horror 5.0
3 Romance 8.5
thank you so much. is there a way to change group.1 and x to another variable?
– Thom JAckson
Mar 9 at 1:32
add a comment |
You can get the table that you are looking for using the aggregate function.
## Your sample data
DF = read.table(text="Genre Score
Horror 4
Horror 6
Romance 7
Fiction 3
Romance 10",
header = TRUE)
Make the table
TAB = aggregate(DF$Score, list(DF$Genre), mean)
names(TAB) = c("Genre", "MeanScore")
TAB
Genre MeanScore
1 Fiction 3.0
2 Horror 5.0
3 Romance 8.5
thank you so much. is there a way to change group.1 and x to another variable?
– Thom JAckson
Mar 9 at 1:32
add a comment |
You can get the table that you are looking for using the aggregate function.
## Your sample data
DF = read.table(text="Genre Score
Horror 4
Horror 6
Romance 7
Fiction 3
Romance 10",
header = TRUE)
Make the table
TAB = aggregate(DF$Score, list(DF$Genre), mean)
names(TAB) = c("Genre", "MeanScore")
TAB
Genre MeanScore
1 Fiction 3.0
2 Horror 5.0
3 Romance 8.5
You can get the table that you are looking for using the aggregate function.
## Your sample data
DF = read.table(text="Genre Score
Horror 4
Horror 6
Romance 7
Fiction 3
Romance 10",
header = TRUE)
Make the table
TAB = aggregate(DF$Score, list(DF$Genre), mean)
names(TAB) = c("Genre", "MeanScore")
TAB
Genre MeanScore
1 Fiction 3.0
2 Horror 5.0
3 Romance 8.5
edited Mar 9 at 1:36
answered Mar 9 at 1:22
G5WG5W
23.6k92244
23.6k92244
thank you so much. is there a way to change group.1 and x to another variable?
– Thom JAckson
Mar 9 at 1:32
add a comment |
thank you so much. is there a way to change group.1 and x to another variable?
– Thom JAckson
Mar 9 at 1:32
thank you so much. is there a way to change group.1 and x to another variable?
– Thom JAckson
Mar 9 at 1:32
thank you so much. is there a way to change group.1 and x to another variable?
– Thom JAckson
Mar 9 at 1:32
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%2f55072956%2fhow-do-i-merge-objects-with-the-same-character-within-a-column%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
2
unique(DF$Genre)– G5W
Mar 9 at 1:01
Let me revise my question sorry about that Let's say I have a DF of just 2 columns "Genre" and "score" within that Genre there are "Horror", "Romance", "Fiction" etc.
Genre Score Horror 4 Horror 6 Romance 7 Fiction 3 Romance 10How do I code so that I can combine the "Horror" objects to just one? So basically, I want the table to showGenre Score Horror mean(score) Romance mean(score) Fiction mean(score)– Thom JAckson
Mar 9 at 1:11