How to conneted same dataframe column? [closed]
i want connect column in same dataframe.
for example,
# I have data type is below
region=c("A","B","C")
Q1=c("ads","qwer","zxcv")
Q2=c("poi","lkj","mnb")
temp=data.frame(region, Q1, Q2)
### i want chaged below
region1=c("A","B","C")
Q=c("ads,poi","qwer,lkj","zxcv,mnb")
temp2=data.frame(region1, Q)
How to do it... ?
r dataframe connect
closed as unclear what you're asking by Wimpel, MLavoie, Umair, greg-449, Rob Nov 13 '18 at 16:11
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
i want connect column in same dataframe.
for example,
# I have data type is below
region=c("A","B","C")
Q1=c("ads","qwer","zxcv")
Q2=c("poi","lkj","mnb")
temp=data.frame(region, Q1, Q2)
### i want chaged below
region1=c("A","B","C")
Q=c("ads,poi","qwer,lkj","zxcv,mnb")
temp2=data.frame(region1, Q)
How to do it... ?
r dataframe connect
closed as unclear what you're asking by Wimpel, MLavoie, Umair, greg-449, Rob Nov 13 '18 at 16:11
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
i want connect column in same dataframe.
for example,
# I have data type is below
region=c("A","B","C")
Q1=c("ads","qwer","zxcv")
Q2=c("poi","lkj","mnb")
temp=data.frame(region, Q1, Q2)
### i want chaged below
region1=c("A","B","C")
Q=c("ads,poi","qwer,lkj","zxcv,mnb")
temp2=data.frame(region1, Q)
How to do it... ?
r dataframe connect
i want connect column in same dataframe.
for example,
# I have data type is below
region=c("A","B","C")
Q1=c("ads","qwer","zxcv")
Q2=c("poi","lkj","mnb")
temp=data.frame(region, Q1, Q2)
### i want chaged below
region1=c("A","B","C")
Q=c("ads,poi","qwer,lkj","zxcv,mnb")
temp2=data.frame(region1, Q)
How to do it... ?
r dataframe connect
r dataframe connect
asked Nov 13 '18 at 7:33
Sung min YangSung min Yang
174
174
closed as unclear what you're asking by Wimpel, MLavoie, Umair, greg-449, Rob Nov 13 '18 at 16:11
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Wimpel, MLavoie, Umair, greg-449, Rob Nov 13 '18 at 16:11
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
temp$Q <- apply(temp[-1], 1, toString)
temp[c("Q1", "Q2")] <- NULL
temp
region Q
1 A ads, poi
2 B qwer, lkj
3 C zxcv, mnb
add a comment |
Using base R you can do:
temp$Q <- paste(temp$Q1, temp$Q2, sep=",")
temp <- temp[,c("region", "Q")]
temp
region Q
1 A ads,poi
2 B qwer,lkj
3 C zxcv,mnb
add a comment |
This would be a solution using the mutate
function from the dplyr
package to create the new column Q
by using paste0
to concatenate the columns Q1
and Q2
. In the end I just removed the columns Q1
and Q2
by using select
with -
:
library(dplyr)
temp %>% mutate(Q = paste0(Q1,", ",Q2)) %>% select(-Q1,-Q2)
oh thank you : )
– Sung min Yang
Nov 13 '18 at 7:46
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
temp$Q <- apply(temp[-1], 1, toString)
temp[c("Q1", "Q2")] <- NULL
temp
region Q
1 A ads, poi
2 B qwer, lkj
3 C zxcv, mnb
add a comment |
temp$Q <- apply(temp[-1], 1, toString)
temp[c("Q1", "Q2")] <- NULL
temp
region Q
1 A ads, poi
2 B qwer, lkj
3 C zxcv, mnb
add a comment |
temp$Q <- apply(temp[-1], 1, toString)
temp[c("Q1", "Q2")] <- NULL
temp
region Q
1 A ads, poi
2 B qwer, lkj
3 C zxcv, mnb
temp$Q <- apply(temp[-1], 1, toString)
temp[c("Q1", "Q2")] <- NULL
temp
region Q
1 A ads, poi
2 B qwer, lkj
3 C zxcv, mnb
answered Nov 13 '18 at 8:16
snoramsnoram
6,399831
6,399831
add a comment |
add a comment |
Using base R you can do:
temp$Q <- paste(temp$Q1, temp$Q2, sep=",")
temp <- temp[,c("region", "Q")]
temp
region Q
1 A ads,poi
2 B qwer,lkj
3 C zxcv,mnb
add a comment |
Using base R you can do:
temp$Q <- paste(temp$Q1, temp$Q2, sep=",")
temp <- temp[,c("region", "Q")]
temp
region Q
1 A ads,poi
2 B qwer,lkj
3 C zxcv,mnb
add a comment |
Using base R you can do:
temp$Q <- paste(temp$Q1, temp$Q2, sep=",")
temp <- temp[,c("region", "Q")]
temp
region Q
1 A ads,poi
2 B qwer,lkj
3 C zxcv,mnb
Using base R you can do:
temp$Q <- paste(temp$Q1, temp$Q2, sep=",")
temp <- temp[,c("region", "Q")]
temp
region Q
1 A ads,poi
2 B qwer,lkj
3 C zxcv,mnb
answered Nov 13 '18 at 7:36
alex_555alex_555
6661315
6661315
add a comment |
add a comment |
This would be a solution using the mutate
function from the dplyr
package to create the new column Q
by using paste0
to concatenate the columns Q1
and Q2
. In the end I just removed the columns Q1
and Q2
by using select
with -
:
library(dplyr)
temp %>% mutate(Q = paste0(Q1,", ",Q2)) %>% select(-Q1,-Q2)
oh thank you : )
– Sung min Yang
Nov 13 '18 at 7:46
add a comment |
This would be a solution using the mutate
function from the dplyr
package to create the new column Q
by using paste0
to concatenate the columns Q1
and Q2
. In the end I just removed the columns Q1
and Q2
by using select
with -
:
library(dplyr)
temp %>% mutate(Q = paste0(Q1,", ",Q2)) %>% select(-Q1,-Q2)
oh thank you : )
– Sung min Yang
Nov 13 '18 at 7:46
add a comment |
This would be a solution using the mutate
function from the dplyr
package to create the new column Q
by using paste0
to concatenate the columns Q1
and Q2
. In the end I just removed the columns Q1
and Q2
by using select
with -
:
library(dplyr)
temp %>% mutate(Q = paste0(Q1,", ",Q2)) %>% select(-Q1,-Q2)
This would be a solution using the mutate
function from the dplyr
package to create the new column Q
by using paste0
to concatenate the columns Q1
and Q2
. In the end I just removed the columns Q1
and Q2
by using select
with -
:
library(dplyr)
temp %>% mutate(Q = paste0(Q1,", ",Q2)) %>% select(-Q1,-Q2)
answered Nov 13 '18 at 7:36
FloSchmoFloSchmo
4486
4486
oh thank you : )
– Sung min Yang
Nov 13 '18 at 7:46
add a comment |
oh thank you : )
– Sung min Yang
Nov 13 '18 at 7:46
oh thank you : )
– Sung min Yang
Nov 13 '18 at 7:46
oh thank you : )
– Sung min Yang
Nov 13 '18 at 7:46
add a comment |