I have an output dataframe that looks like this:
After summing the values in the “Flux” column and a couple other analyses I get an output that looks like this. This is a summarized version of the original dataframe.
I need the new output to include the “Treatment” column in from the first output. So that the final dataframe has three columns: ID, Total_CO2, Treatment Does anyone know how to do this?
Related
I have two data frames Name_List and Fruits_List. I would like to produce the dataframe Output. Output in such a way that Name should repeat based on the values in Rows_to_repeat column. Please let me know if anyone has the solution.
Name=c("rohit","murali","partha")
Rows_to_repeat=c(6,3,1)
Fruits=c("Apple","Orange","Watermelon","Mango","Banana","Kiwi","Pomo","Dates","Muskmelon","Papaya")
Person_Got_Fruit=c("rohit","rohit","rohit","rohit","rohit","rohit","murali","murali","murali","partha")
Name_List=data.frame(Name,Rows_to_repeat)
Fruits_List=data.frame(Fruits)
Output=data.frame(Fruits,Person_Got_Fruit)
This is the Solution which is working for me
Person_Got_Fruit=data.frame(rep(Name_List$Name, Name_List$Rows_to_repeat))
Output=cbind(Fruits_List,Person_Got_Fruit)
I am trying to work with the below data frame and what I am trying to do is to compare the values from columns:
#create a sample data frame
df<-data.frame(
item=c("a","b","c","d"),
price_today=c(1,2,3,4,5),
price_yesterday=c(1,2,3,4,5)
If values from column price_today are the same compared with values from column price_yesterday, then print okay or else print not okay, and the printed result will be shown as a new variable in the data frame.
May I know how should I go about the ifelse part here?
Many thanks for your help and have a good day.
Modified Questions:
Hi all, so now what if the df becomes like this:
#create a sample data frame (modified)
df<-data.frame(
item=c("a","a","c","d"),
price_today=c(1,"",3,"XYZ",5),
price_yesterday=c(1,2,3,4,5)
Now it contains both blank value and non-numerical values in column price_today. And instead of a,b,c,d in column item, it becomes a,a,c,d in column item. I have been trying to do the following:
Sort column item by "a" and I have the below code:
df_1<-df[df$item=="a",]
After df_1 is filtered, then again sort price_today, by removing blank and non-numerical values with codes below:
df_1<-df[!is.numeric(df_1$price_today),]
I am able to filter out by "a" in column item, however, with the second filter, it then returns with the original df, may I know what did I do wrong here?
Million thanks for your help and have a good day/night.
This probably has a simple fix, but I'm relatively new to using R and could use some assistance.
The toy data I'm using for a gene network analysis has rows that look like this:
whereas the data that I've uploaded has rows that look like this:
.
The code I'm using refers to the row names to map on as gene names. I am able to successfully run this analysis, however, the output I end up with has lists of row numbers where there should be lists of gene names.
Is there a simple way that I can convert my data into the toy data format so that the row names are gene names instead of numbers?
probabily it is refusee.
I want to transpose a data frame that has both numeric and character columns. I have some lines where the id is repeated 2 or even more times. I would like to have a final dataframe where I have this data in one line.
I thought about using both the data.table and reshape2 library (they have similar functions) but I can't find the right combination to do what I want and I'm going crazy. Could someone give me some help?
Here a modified example of my database
example_data <-data.frame(cod=c(20,20,20,20,20,20,20,40,80,80,80,80,80,240),
id=c(44,68,137,150,186,236,289,236,44,150,155,236,68,289),
textVar=c('aaaa','aaaa','aaaa bbbb','aaaa','cccc','cccc','cccc bbb','dddd','dddd cccc','dddd','ffff','ffff gggg','ffff','hhhh'),
ww=c(4,4,4,4,4,4,4,45,118,118,118,118,118,118))
If for example consider the column with id=44 my output is like this:
exampleRow <-data.frame(cod_1=c(20),id=c(44),textVar_1=c('aaaa'),ww_1=c(4),cod_2=c(80),id=c(44),textVar_2=c('dddd cccc'),ww_2=c(118))
Suppose I have a dataframe with a large number of observations of 6 variables. The source dataframe looks like this:
I need a new dataframe with TOP10 ordered by frequency TDT_PRD_ID (unique values).
I tried to return one values using apply function like this:
apply(data, 2, function(x) names(which.max(x)))
but I don't know how to create TOP10. Can you help me, please?
I need something like this:
view
If you're just trying to sort by TDT_QTY then you can just do (assuming you want the most frequent first):
TOP10 <- data[order(data$TDT_QTY,decreasing=TRUE),]
And if you only want the top 10 after that:
TOP10[1:10,]