similar to: Colsplit, removing parts of a string

Displaying 20 results from an estimated 4000 matches similar to: "Colsplit, removing parts of a string"

2013 Jan 11
3
split & rbind (cast) dataframe
Hi, I would like to split dataframe based on one colum and want to connect the two dataframes by rows (like rbind). Here a small example: # The orgininal dataframe df1 <- data.frame(col1 = c("A","A","B","B"),col2 = c(1:4), col3 = c(1:4)) # The datafame how it could look like df2 <- data.frame(A.col2 = c(1,2), A.col3 = c(1,2), B.col2 = c(3,4), B.col3
2008 Jun 13
1
help with colsplit (reshape)
Dear list, I'm trying to figure out how to use the reshape package to reshape data from a "wide" format to a "long" format. I have data like this pid <- c(1:10) predA <- c(-1,-2,-1,-2,-1,-2,-1,-2,-1,-2) predB.1 <- c(0,0,0,1,1,0,0,0,1,1) predB.2 <- c(2,2,3,3,3,2,2,3,3,3) predC.1 <- c(10,10,10,10,10,11,11,11,11,11) predC.2 <-
2013 Jan 11
2
Merging list of dataframes with reshape merge_all
Hi, I'd like to merge mutliple dataframes from a list of dataframes by some common columns. The approach for simply merging 2 dataframes is working with: merge(df1,df2,by=c("col1","col2","col3"),all=TRUE) For mutliple dataframes in a list I try to use the merge_all command from the package reshape. The documentation states that the command takes a list of
2013 Mar 13
5
string split at xth position
Hi, I have a vector of strings like: c("a1b1","a2b2","a1b2") which I want to spilt into two parts like: c("a1","a2","a2") and c("b1","b2,"b2"). So there is always a first part with a+number and a second part with b+number. Unfortunately there is no separator I could use to directly split the vectors.. Any idea
2012 Dec 11
5
Renaming column names according to another dataframe
Hi, I've got a dataframe having a code as column name. Addtionally I have another dataframe with a two columns (and lots of rows), the first containing the code and the second some Text (real name). Now I'd like to use the information (pairs of code and name) of the second dataframe to rename all the columnnames in the first dataframe. How is it possible to achieve that? Here a small
2008 Sep 14
5
difference of two data frames
Hello I have 2 data frames DF1 and DF2 where DF2 is a subset of DF1: DF1= data.frame(V1=1:6, V2= letters[1:6]) DF2= data.frame(V1=1:3, V2= letters[1:3]) How do I create a new data frame of the difference between DF1 and DF2 newDF=data.frame(V1=4:6, V2= letters[4:6]) In my real data, the rows are not in order as in the example I provided. Thanks much Joseph [[alternative HTML version
2013 Feb 26
2
merging or joining 2 dataframes: merge, rbind.fill, etc.?
#I want to "merge" or "join" 2 dataframes (df1 & df2) into a 3rd (mydf). I want the 3rd dataframe to contain 1 row for each row in df1 & df2, and all the columns in both df1 & df2. The solution should "work" even if the 2 dataframes are identical, and even if the 2 dataframes do not have the same column names. The rbind.fill function seems to work. For
2011 Aug 18
2
Best way/practice to create a new data frame from two given ones with last column computed from the two data frames?
Dear expeRts, What is the best approach to create a third data frame from two given ones, when the new/third data frame has last column computed from the last columns of the two given data frames? ## Okay, sounds complicated, so here is an example. Assume we have the two data frames: df1 <- data.frame(Year=rep(2001:2010, each=2), Group=c("Group 1","Group 2"), Value=1:20)
2012 Jul 11
4
Help with loop
Hi, I have two dataframes: The first, df1, contains some missing data: cola colb colc cold cole 1 NA 5 9 NA 17 2 NA 6 NA 14 NA 3 3 NA 11 15 19 4 4 8 12 NA 20 The second, df2, contains the following: cola colb colc cold cole 1 1.4 0.8 0.02 1.6 0.6 I'm wanting all missing data in df1$cola to be replaced by the value of df2$cola.
2013 Jan 02
2
rbind: inconsistent behaviour with empty data frames?
The rbind on empty and nonempty data frames behaves inconsistently. I am not sure if by design. In the first example, first row is deleted, which may or may not be on purpose: df1 <- data.frame() df2 <- data.frame(foo=c(1, 2), bar=c("a", "b")) rbind(df1, df2) foo bar 2 2 b Now if we continue: df1 <- data.frame(matrix(0, 0, 2)) names(df1) <- names(df2)
2009 Jan 21
3
merging several dataframes from a list
Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 <- data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) <- c("pos", "data") df3 <- df2 <- df1 df2$data
2008 Feb 10
11
data frame question
Hello I have 2 data frames df1 and df2. I would like to create a new data frame new_df which will contain only the common rows based on the first 2 columns (chrN and start). The column score in the new data frame should be replaced with a column containing the average score (average_score) from df1 and df2. df1= data.frame(chrN= c(“chr1”, “chr1”, “chr1”, “chr1”, “chr2”, “chr2”, “chr2”),
2010 Dec 16
2
Compare two dataframes
Hello, I have two dataframes DF1 and DF2 that should be identical but are not (DF1 has some rows that aren't in DF2, and vice versa). I would like to produce a new dataframe DF3 containing rows in DF1 that aren't in DF2 (and similarly DF4 would contain rows in DF2 that aren't in DF1). I have a solution for this problem (see self contained example below) but it's awkward and
2011 Apr 30
3
indexing into a data.frame using another data.frame that also contains values for replacement
Hello all, I have a quandry I have been scratching my head about for a while. I've searched the manual and the web and have not been able to find an acceptable result, so I am hoping for some help. I have two data frames and I want to index into the first using the second, and replace the specific values I have indexed with more values from the second data.frame. I can do this
2012 Aug 14
4
Subsetting rows by multiple levels of selected values
Dear list, Let's say we have a data frame as follows, >expand.grid(a=1:5,b=c(1,5,10,20),DV=c(0.1,0.2,0.3))->df1 >df1$DV<-rgamma(60,shape=10) columns a and b are two levels. DV is the column with values we are interested in. Then another data frame df2 with values as follows data.frame(a=c(2,2,3,4,5),b=c(5,10,1,5,20))->df2 Now I want to a subset of df1 that match df2 at the
2010 Nov 05
4
assignment operator saving factor level as number
Hi all, I have a dataframe (df1) that I am trying to select values from to a second dataframe that at the current time is only for the selected items from df1 (df2). The values that I am trying to save from df1 are factors with alphanumeric names df1 looks like this: 'data.frame': 3014 obs. of 13 variables: $ Num : int 1 1 1 2 2 2 3 3 3 4 ... $ Tag_Num : int 1195
2012 Jun 03
2
merging single column from different dataframe
Hi all, probably really simple to solve, but having no background in programming I haven't been able to figure this out: I have two dataframes like df1 <- data.frame(names1=c('aa','ab', 'ac', 'ad'), var1=c(1,5,7,12)) df2 <- data.frame(names2=c('aa', 'ab', 'ac', 'ad', 'ae'), var2=c(3,6,9,12,15)) Now I want merge
2017 Oct 10
1
About multiple panels with limited space in-between
Hi R users, I have a question about plotting. The following two datasets are an example. What I have in mind is like the attached figure, but just have two rows, top row is for DF1, bottom row is for DF2. The top and bottom rows, have x-axis as var1, var2, var3, etc, while the y-axis represents A. For each row, only the leftmost panel has y-axis ticks and label. For the two rows, only the bottom
2009 Mar 22
5
If statement generates two outputs
Hi, How do I tell an if statement to generate two seperate outputs. E.g If X>5 I want to create df1 and df2: if (X>5) {df1<-c(4,5,6,7,8) AND df2<-c(9,10,11,12,13)} Thanks, James -- View this message in context: http://www.nabble.com/If-statement-generates-two-outputs-tp22650844p22650844.html Sent from the R help mailing list archive at Nabble.com.
2007 Oct 02
4
Strange names when creating a data.frame: Difference between <- and =
This is just a curiosity question. Why do the two different syntaxes for df1 and df2 give such different results in the names(dfx)? Thanks df1 <- data.frame(nas = c("A", "B" , "B" ,"C" ,"B", "A", "D"),nums = c(3, 2, 1, 1, 2, 3, 7)) df2 <- data.frame(nas <- c("A", "B" ,