similar to: Modifying a data frame based on a vector that contains column numbers

Displaying 20 results from an estimated 3000 matches similar to: "Modifying a data frame based on a vector that contains column numbers"

2010 Nov 03
2
avoiding too many loops - reshaping data
Hello! I have a data frame like this one: mydf<-data.frame(city=c("a","a","a","a","a","a","a","a","b","b","b","b","b","b","b","b"),
2008 Mar 28
3
Converting a data frame to matrix
Hello: I have a tab delim file with 100 rows and 100 columns. I have numerical values in this table. What I want is to create an image color map with color gradation. my values range from -5 to 0. max value is 0. to acheive this, I need to convert my data.frame into matrix. I tried following : mydf <- read.table('mytable',sep='\t',header=T) mydf1 <- mydf[,2:100]
2011 May 19
1
Creating a "shifted" month (one that starts not on the first of each month but on another date)
Hello! I have a data frame with dates. I need to create a new "month" that starts on the 20th of each month - because I'll need to aggregate my data later by that "shifted" month. I wrote the code below and it works. However, I was wondering if there is some ready-made function in some package - that makes it easier/more elegant? Thanks a lot! # Example data:
2007 May 17
2
How to select specific rows from a data frame based on values
Dear Group: I am working with a data frame containing 316 rows of individuals with 79 variables. Each of these 79 variables have values that range between -4 to +4, and I want to subset this data frame so that in the resulting new dataframe, values of _all_ of these variables should range between -3 and +3. Let's say I have the following dataframe (it's a toy example with 4 individuals
2012 Dec 06
4
Assignment of values with different indexes
I would like to take the values of observations and map them to a new index. I am not sure how to accomplish this. The result would look like so: x[1,2,3,4,5,6,7,8,9,10] becomes y[2,4,6,8,10,12,14,16,18,20] The "newindex" would not necessarily be this sequence, but a sequence I have stored in a vector, so it could be all kinds of values. here is what happens: > x <- rnorm(10)
2008 Dec 20
1
How to do indexing after splitting my data-frame?
Hello, after splitting a data-frame I want to access the results. Maybe the problem is, that the factor/index is a string... ...or do I miss knowing details of the index-uasge? Please look and help: ======================================= > weblog <- read_weblog("web.log") > > > str(weblog) 'data.frame': 2247 obs. of 18 variables: $ host : Factor w/ 77
2010 Oct 25
2
Find index of a string inside a string?
Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index("abcd", "bcd") will return 2 because bcd is located in the 2nd cell of the abcd string. The equivalent in R should do this: > myIndex <- foo("abcd", "bcd") #return 2. What is the function that I am looking for? I want to use the return value in substr, like I do
2009 Sep 23
2
Function to check if a vector contains a given value?
Dear R'rs, is there a function that checks if a given vector contains a certain value. E.g., x<-c(1,2,3,4). How can I get a TRUE or FALSE for whether x contains a 2? -- Dimitri Liakhovitski Ninah.com Dimitri.Liakhovitski at ninah.com
2012 Oct 08
3
turn list into dataframe
Dear R users, I'm starting to use 'apply' functions rather than for loops in R, and sometimes the output is a bit different than what I want. In this case, the command was tapply(myvector,myindex,cumsum) And the output was something like this: $`SNRL1 Core 120` [1] 2.8546 4.0778 5.2983 6.3863 7.5141 8.5498 9.5839 10.6933 $`SNRL1 Core 230` [1] 7.6810 8.7648 9.8382
2017 Oct 14
2
Populate one data frame with values from another dataframe for rows that match
Dear @Rui Barradas, thank you for the solution. It works perfectly. On 13/10/2017, 23:35, "Rui Barradas" <ruipbarradas at sapo.pt> wrote: Hello, Try the following. myDF1$studyno <- as.character(myDF1$studyno) myDF2$studyno <- as.character(myDF2$studyno) i1 <- which(names(myDF1) == "pf_mcl") merge(myDF1[-i1], myDF2,
2017 Oct 13
4
Populate one data frame with values from another dataframe for rows that match
I'm trying to populate the column ?pf_mcl? in myDF1 with values from myDF2, where rows match based on column "studyno" but the solutions I have found so far don't seem to be giving me the desired output. Below is a snapshot of the data.frames. myDF1 <- structure(list(studyno = c("J1000/9", "J1000/9", "J1000/9", "J1000/9",
2017 Oct 14
0
Populate one data frame with values from another dataframe for rows that match
Hi Kevin, I think there are issues with Rui's proposed solution. For example, if there are rows in myDF1 which have a studyno which does not match any row in myDF2, then you will lose those rows. In your original request you said that you wanted to keep those rows. To demonstrate my point I need to modify your sample data. Specifically, I changed some studyno settings in myDF1, and also the
2017 Oct 13
0
Populate one data frame with values from another dataframe for rows that match
Hello, Try the following. myDF1$studyno <- as.character(myDF1$studyno) myDF2$studyno <- as.character(myDF2$studyno) i1 <- which(names(myDF1) == "pf_mcl") merge(myDF1[-i1], myDF2, by = "studyno") Hope this helps, Rui Barradas Em 13-10-2017 20:09, Kevin Wamae escreveu: > I'm trying to populate the column ?pf_mcl? in myDF1 with values from myDF2, where rows
2017 Oct 14
2
Populate one data frame with values from another dataframe for rows that match
Dear @Bert Gunter<mailto:bgunter.4567 at gmail.com>, I tried merge and I faced many challenges. @Rui Barradas<mailto:ruipbarradas at sapo.pt> solution is working. From: Bert Gunter <bgunter.4567 at gmail.com> Date: Friday, 13 October 2017 at 22:44 To: Kevin Wamae <KWamae at kemri-wellcome.org> Cc: R-help <R-help at r-project.org> Subject: Re: [R] Populate one data
2017 Jul 27
2
na.rm = T treatment by ggplot2's geom_bar
I think you should be more suspicious of yourself, Dimitri. A letter T variable can easily arise in the problem domain when you are not thinking of logical values at all, at which point your cavalier use of T as a synonym for TRUE can suddenly become a bug. -- Sent from my phone. Please excuse my brevity. On July 27, 2017 8:18:03 AM PDT, Dimitri Liakhovitski <dimitri.liakhovitski at
2008 Sep 08
7
Question about multiple regression
Dear R-list, maybe some of you could point me in the right direction: Are you aware of any FREE Fortran or Java libraries/actual pieces of code that are VERY efficient (time-wise) in running the regular linear least-squares multiple regression? More specifically, I have to run small regression models (between 1 and 15 predictors) on samples of up to N=700 but thousands and thousands of them. I
2013 Jun 08
1
splitting a string column into multiple columns faster
Hello! I have a column in my data frame that I have to split: I have to distill the numbers from the text. Below is my example and my solution. x<-data.frame(x=c("aaa1_bbb1_ccc3","aaa2_bbb3_ccc2","aaa3_bbb2_ccc1")) x library(stringr) out<-as.data.frame(str_split_fixed(x$x,"aaa",2)) out2<-as.data.frame(str_split_fixed(out$V2,"_bbb",2))
2017 Oct 15
1
Populate one data frame with values from another dataframe for rows that match
Dear @William<mailto:wdunlap at tibco.com>, thanks for the feedback. I have tested it on the larger dataset and noticed that it created two variables, pf_raw and pf_curated. The output we were looking for, was one that takes the variable pf_mcl in curated dataset and replaces pf_mcl in matching rows within the raw dataset. @Eric<mailto:ericjberger at gmail.com>?s solution was able to
2017 Jul 27
2
na.rm = T treatment by ggplot2's geom_bar
Just a thought: Did you try na.rm = TRUE in case you have an object named "T" in scope? -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Jul 27, 2017 at 7:49 AM, Dimitri Liakhovitski <dimitri.liakhovitski at
2017 Jul 27
3
na.rm = T treatment by ggplot2's geom_bar
Hello! I am trying to understand how ggplot2's geom_bar treats NAs. The help file says: library(ggplot2) ?geom_bar na.rm: If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed. I am trying it out: md <- data.frame(a = c(letters[1:5], letters[1:4], letters[1:3], rep(NA, 3))) str(md); levels(md$a) ggplot(data = md, mapping = aes(x =