This question already has answers here:
How to reshape data from long to wide format
(14 answers)
Closed 2 years ago.
Suppose I have the following dataframe in R
I would like the dataframe to become
How do I do this?
Yeah, pivotwider was what I needed.
Related
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
This question already has answers here:
How to reshape data from long to wide format
(14 answers)
Closed 4 years ago.
I have a tibble that I'm trying to separate into multiple columns:
The tibble only has one column and should look like the right side of the image when done.
It can be done with matrix (assuming that the length of column is a multiple of 4)
matrix(data$col1, ncol=4, byrow = TRUE)
This question already has answers here:
dplyr - using mutate() like rowmeans()
(8 answers)
Closed 4 years ago.
I currently have a table in R with 4 columns and I want to average the last two columns (titled W10CP1 and W10CP2) into a 5th column of that table.
I tried to use rowMeans but I got an error.
Sorry for the basic question!
You can try use the tydeverse package here an example:
library(tidyverse)
data<-data%>%
mutate(mean= (data[,-1] +data[,-2]/2))
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.
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=';')