I have a list named "binom" that looks as follows:
"estimate_" values are probabilities that I want to reverse (to do a calculation "1-value"). How to mutate these values in this list?
I googled but did not find a code for doing this. I need the list afterwards as a list for plotting.
Try looking at ?base::transform or ?dplyr::mutate
You will first need to subset your list to the element you want to manipulate:
library(dplyr)
binom[[1]] %>%
mutate(newcol = 1 - estimate_)
You can learn more about data transformation here
In the future, it's helpful to provide a mock dataset with your question instead of a screenshot, so that people have something to work with when attempting to answer your questions.
Related
how are you?
I have the next problem, that is very weird because the task it is very simple.
I want to filter one of my factor variables in R, but the outcome is an empty dataframe.
So my data frame is called "data_2022", if i execute this code:
sum(data_2022$CANALDEVENTA=="WEB")
The result is 2704800 that is the number of times that this filter is TRUE.
a= data_2022 %>% filter(CANALDEVENTA=="WEB")
This returns an empty data frame.
I know i am not an expert in R, but i have done the last thing a million times and i never had this error before.
Do you have a clue about whats the problem with this?
Sorry i did not make a reproducible example.
Already thank you.
you could use subset function:
a<-subset(data_2022, CANALDEVENTA=="WEB")
using tidyverse, make sure you are using the function from dplyr::filter. filter is looking for a logical expression but probably you apply it to a data.frame. Try this code too:
my_names<-c("WEB")
a<-dplyr::filter(data_2022, CANALDEVENTA %in% my_names)
Hope it works.
I am trying to categorize genes with multiple GO descriptors into bins based on what those GO descriptors are related to. I have dataframe A which contains the raw data associated with a list of geneIDs (>500,000) and their associated GO descriptors and dataframe B which classifies these GO descriptors into larger groups.
Example of dataframe A
dfA
Example of dataframe B
dfB
Ideally, the final output would reference the entire list and generate a new column in dataframe A classifying the GeneIDs into the GO_Category's associated with its specific GO_IDs -- bonus points if it removes duplicate hits on the GO_Categorys.
Looking something like this...
Example of Ideal Solution
However, I know that the ideal solution might be difficult to obtain, and I already have dataframe B listed out based on the unique GO_Categories so a solution like this might be easier to obtain.
Example of Acceptable Solution
So far I have struggled with getting any command to search for partial strings using a list from another dataframe with the goal of returning all matches.
I have had partial success with the acceptable solution approach and using:
dfA <- dfA %>%
mutate(GO_Cat_1 = c('No', 'Yes')[1+str_detect(dfA$GO_IDs, as.character(dfB$GO_IDs))])
The solution seems okay, however, it does return an error along the lines of
problem with mutate() column GO_Cat_1.
i GO_Cat_1 = ...[].
i longer object length is not a multiple of shorter object length
I have also tried to look into applying grepl/grep - but struggled to feed it a list of terms to look for partial string matches in dfA.
Any assistance is greatly appreciated!
I want to extract a dataframe from a list that is also inside a list. Also some dataframes have different number of columns than others. This is what i have used without success.
Name of the first list is comments.
df <- do.call(rbind.fill,comments)
When i try
df <- do.call(rbind.fill,comments[[1]])
it does work, but i would like for all the dataframes to be together as one.
I know that this is not a reproducible example, but please bear with me, as this would take some time to repproduce, and i think the problem is clear enough.
Thanks
I have two different data frames, each of them consisting of a list of "genes" and a list of "interactors" (other genes). Is it possible with R to check if there any "genes" from one list that are also present in any of the columns of "interactors" from the other data frame, and vice-versa?
I am quite new in R, so perhaps there is an easy way to perform this, but I don't even know how to look for it.
Thanks in advance!
Guillermo.
please can you show a sample of your data?
In any case, I guess the following is what you need:
df_common<-data.frame(df[which(df$genes %in% df$interactors),])
it is checking which elements in the column "genes" in the data frame df are also present %in% the column "interactors" in the same data frame
Is it this what you are looking for? if not, please paste input and desired output
all.
I´m trying to extract a vector from a column that contains all the values that belong to a specific type.
To be more concise, I have a table with 5000 rows. The column "Types" can take the values A,B,C or D. I need to extract all the rows that belong to a specific type, like A.
I want to use the function group_by from the library dplyr and I´m trying:
dplyr::group_by(my_database,type)
or even
dplyr::group_by(my_database,type,A)
but I don´t get what I need. Does anyone know how to proceed?
NOTE: I can´t use the function %>% because for some strange reason R says "could not find %>% function".
I appreciate a lot your kind responses in advance.
R can't find %>% because you have not loaded a library which uses it. For example:
library(dplyr)
The function that you're looking for is filter.
my_database %>% filter(Types == "A")
Spend some time with the dplyr documentation (introduction) or a good tutorial.