I also want to rename column 'X' to 'gene names' . How can i do it?
I have this data frame :
and I want to remove those rows which contain NA values from the log2fold change column
How can I do this through R?
2 answers
Hi Anas,
If your data frame is called res, then:
res[!is.na(res$log2FoldChange),]
Kevin
colnames(res)[1] <- 'gene names'
...or:
idx <- which(colnames(res) == 'X')
idx
colnames(res)[idx] <- 'gene names'
I am trying this to make a heatmap:
ntd <- normTransform(dds)
library("pheatmap")
select <- order(rowMeans(counts(dds,normalized=TRUE)),
decreasing=TRUE)[1:50]
df <- as.data.frame(colData(dds)[,c("group")])
pheatmap(assay(ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
cluster_cols=FALSE, annotation_col=df)
But it is giving me this error:
Error in check.length("fill"): 'gpar' element 'fill' must not be length 0
The data frame which I am using for annotation is:
kindly help me
Hi,
For dataframe manipulation you should look into the dplyr and tidyr libraries. You can take a look a this cheatsheet for example.
You can remove NAs and rename columns as follows:
library(dplyr)
your_dataframe %>%
dplyr::filter(!is.na(log2FoldChange)) %>%
dplyr::rename(gene_names = X)
No need to load dplyr if you call it's functions directly though. Ü
It helps avoiding confusion, since these functions also exist in other libraries
ponganta means you don't need the library(dplyr) step if you call functions like this dplyr::filter()...
whatever, %>% need this. :-D
Agreed, especially regarding dplyr::rename(). I didn't think about that.
Regarding these two functions, there are oftentimes namespace collisions with other packages, I guess this is what @rioualen meant. Good catch.
Log in to answer this question.