Is there any way to turn a column into a string? [duplicate] - r

This question already has answers here:
How do I paste string columns in data.frame [duplicate]
(2 answers)
Closed 5 years ago.
For example, if I have a data set
data.frame(x = c("a","b","a","b","c"))
how can I get a output =
a,b,a,b,c in a list or text.

paste(data_frame,collapse=",") will collapse the column into a single string.

Related

How do I edit the values in my data frame to remove numerical values? [duplicate]

This question already has answers here:
Remove numbers at the beginning and end of a string
(3 answers)
How to remove beginning-digits only in R [duplicate]
(3 answers)
Closed last month.
I have a data frame that looks like this:
In the "x" column, I want to remove the number values and just have the string character, i.e. "Benign_freq" or "Recessive". Is there a way to edit these values using R?

replacing a specific value in data frame [duplicate]

This question already has answers here:
Replace given value in vector
(8 answers)
How do I change a single value in a data.frame?
(4 answers)
How to change a single value in a data frame in R
(4 answers)
How to change a cell value in data.frame
(2 answers)
Closed 4 months ago.
I have the following data frame:
df <- data.frame(
item=c("a","","a","d","e"),
price_today=c(1,2,"THREE%%",4,"SIX/SIX"))
If I would like to select "THREE%%" and "SIX/SIX" in column price_today and convert them to "3?3" and "6?6", respectively, how should I go about it?

How to drop multiple columns with similar names in a data frame [duplicate]

This question already has answers here:
How to drop columns by name pattern in R?
(6 answers)
Remove columns that contain a specific word
(5 answers)
Closed 3 years ago.
My data set has about 100 columns and some of them (about 25) are called similar but not them same. I'd like to delete all columns that start with "reads_per_million" because write this is so impractical:
data_tumor <- data_tumor[,-c(3,5,7,13,15,22,33,54,65,34,**etc,etc**)]
Thank you so much

How to extract number from string? [duplicate]

This question already has answers here:
stringr extract full number from string
(1 answer)
Extracting unique numbers from string in R
(7 answers)
Extracting numbers from vectors of strings
(12 answers)
Closed 3 years ago.
I have
strQuestions <- c("Q1", "Q22")
I need to get
nQuestions <- c(1,22)
How can I do it nicely? (with stringr?). Thank you
With stringr:
str_sub(strQuestions, 2, 3)
stringr::str_remove_all(strQuestions,"[A-Za-z]")
You can add the function as.numeric() after.

combine objects of data frame in r [duplicate]

This question already has answers here:
Concatenate a vector of strings/character
(8 answers)
Closed 5 years ago.
I have a data frame like this:
I want to convert those objects to a long string like this, without the column's name salary:
23400;26800;9878;6754;7654;28907;6679
What should I do?
Assuming your data.frame is called x:
paste0(x$salary,collapse=';')

Resources