similar to: Inserting column in between -- "better" way?

Displaying 20 results from an estimated 1000 matches similar to: "Inserting column in between -- "better" way?"

2018 May 10
3
Fill down a new column in data frame with a number
Hi, I am a begginer in R programming. I am traying to create a a column in my data frame filled down with a number. > df$newcolumn <- number How can I do it? I am considering use rep() but in this case it is necessary know the number of rows in each data base that I have and I would like to do it in a faster ( and more elegant) way. TKs [[alternative HTML version deleted]]
2013 Jan 08
1
incrementation within ifelse
Dear R-helper, I am working on a very large data frame and I am trying to add a new column and write in it with certain conditions. I have try to use this code with the data frame p : ID = 0 p[,"newColumn"]<- ifelse (p$flagFoehn3_durr == 1, ifelse(p$Guetsch == 0, ID <<- ID ++ , ID ) , 0 ) What I am trying to do
2011 Jul 14
5
Adding rows based on column value
Dear all, I have one problem and did not find any solution.(I have also attached the problem in text file because sometimes column spacing is not good in mail) I have a file(file.txt) attached with this mail.I am reading it using this code to make a data frame (file)- file=read.table("file.txt",fill=T,colClasses = "character",header=T) file looks like this- Chr Pos
2012 Jul 24
5
First value in a row
Hi. This is likely a trivial problem but have not found a solution. Imagine the following dataframe: Lat Lon x1 x2 x3 01 10 NA NA .1 01 11 NA .2 .3 01 12 .4 .5 .6 I want to generate another column that consist of the first value in each row from columns x1 to x3. That is NewColumn .1 .2 .4 Any input greatly appreciated, Thanks, Camilo Camilo Mora, Ph.D.
2011 Aug 03
0
Combining multiple dependent variables for machine learning -- fortunes candidate?
I thought Sarah's reply was great and, alas, should probably be templated for this list. Not sure it fits as a fortunes package entry, but I thought it at least worthy of consideration. Cheers, Bert >> ... >> I appreciate any suggestions for this problem. Sarah Goslee replied: > Suggestions? Yes. Read the posting guide and follow it. It isn't clear that > this is even
2004 Jul 19
10
How to compare X1 = X2 = ... = Xn?
Dear All, I have a data frame with n columns: X1, X2, ., Xn. Now I want to create a new column: if X1 = X2 = . = Xn, the value is 1; Otherwise, the value is 0. How to do that in a quick way instead of doing (n choose 2) comparisons? Thank you, Frank [[alternative HTML version deleted]]
2006 Sep 13
7
inserting columns in the middle of a dataframe
Dear R users: Is there a built-in and simple way to insert new columns after other columns in a dataframe? I.e. currently I have: V1 V2 V3 V4 [1,] [2,] Etc. But I want V1 V5 V2 V3 V4 [1,] [2,] Etc. Can this be done in one line? Jon Minton [[alternative HTML version deleted]]
2011 Aug 22
3
automatic file input
Dear all, I have 100 files which are used as input.and I have to input the name of my files again and again.the name of the files are 1.out, 2.out......100.out. I want to know if there is anything like perl so that i can use something like this- for($f = 1; $f <= 100; $f++) { $file = $f.".out"; I have tried this thing in R but it does not work.Can somebody please help me.
2011 Jul 01
13
For help in R coding
Dear all, I am doing a project on variant calling using R.I am working on pileup file.There are 10 columns in my data frame and I want to count the number of A,C,G and T in each row for column 9.example of column 9 is given below- .a,g,, .t,t,, .,c,c, .,a,,, .,t,t,t .c,,g,^!. .g,ggg.^!, .$,,,,,.,
2012 Jun 10
3
Data.frames can not hold objects...What can be done in the following scenario?
R-Help community, I understand that data.frames can hold elements of type double, string etc but NOT objects (such as a matrix etc). This is not convenient for me in the following situation. I have a function that takes 2 inputs and returns a vector: testfun <- function (x,y) seq(x,y,1) I have a data.frame defined as follows: testframe<-data.frame(xvalues=c(2,3),yvalues=c(4,5)) I would
2011 Jul 05
3
Output data frame using write.table
Dear all, I have a data frame whose name is m1. I want to write this data frame in text file as output.I am using this code- write.table(m1, file = "kas.txt", append = FALSE,row.names=F,quote=F,sep="\t") When I am opening my kas.txt file,the column names are not coming exactly above the column. What should I do.Please help me. Thanking you, Warm Regards Vikas Bansal Msc
2011 Aug 07
3
Printing data frame with million rows
Dear all, I was working on number of files and at the end I got a data frame with approx. million rows.To prin this data frame in output, I used capture.output(print.data.frame(end,row.names=F), file = "summary", append = FALSE) where end is the name of my data frame and summary is the name of my output file. but when I checked the output there were only 10000 rows and at the last it
2007 Dec 06
0
alternatives to latex() or xtable()
An alternative solution that allows you to break it down by categories is in the functions below. Comments/suggestions welcome and encouraged. Note that much thanks is due to those who responded to an earlier post of mine on a similar topic. To use (assuming you have a data.frame falled pathDist with columns distances (your numeric data of interest), Capacity, Surface, and SITE (vectors of
2011 Oct 31
3
Plot two matrices and keeping the record of row names
Dear all, I have two data frames- x1 and y1 with same row names and column names(actually the names of the patients). x1 a b c d e a 1.0000000 0.4730679 0.6226994 0.6036036 0.6433333 b 0.4730679 1.0000000 0.6227273 0.6303855 0.5730858 c 0.6226994 0.6227273 1.0000000 0.7290503 0.6900585 d 0.6036036 0.6303855 0.7290503 1.0000000
2011 Jul 24
2
Deleting rows and store the deleted rows in new data frame
Dear all, I am using grep but I did not understand the problem as I am doing something wrong.Please help me. I am using this code- sf=data.frame(sapply(df[],function(x) grep('\\.&\\,', df[,9]))) the thing is i have a data frame(df) like this- 10 135349467 g G 4 0 0 5 ,,,., 10 135349468 t T 2 0 0 5 ,,c., 10 135349469 g G 7 0 0 5 ,,a., 10 135349470 c C 8 0 0 5 ,,,., 10 135349471
2011 Aug 07
1
Removing funny characters from a column of a data frame
Dear all, The 5th column of my data frame is like this- .$.$.$.$.$,$,$...,,,,,.,,.,,...,,,,.,,....,,,T...,,,,,,,,,,,.,,,,,....,,...,, ,..,,....,,,,,...,,,..,,......,,,,,,,....,,,.,,,,....,,...G.,,,,,,,,...,,,,,,.,, ,t.,,c,,.a.,,,.A,,,,....,,,.....,,,,..........,,,,,..,,,.,,,....,,,,,...,,,$.... .,,,,..,,,...,,,,,..,,,,,,.............$..,,,,,,...,,..,,$,...,,,,,,,....,,,,,,.
2010 May 17
1
suggestions/improvements for recoding strategy
I am recoding some data. Many values that should be 1.5 are recorded as 1-2. Some example data and my solution is below. I am curious about better approaches or any other suggestions. Thanks! # example input data myData <- read.table(textConnection("id, v1, v2, v3 a,1,2,3 b,1-2,,3-4 c,,3,4"),header=TRUE,sep=",") closeAllConnections() # the first column is IDs so remove
2009 May 26
1
Bug in "$<-.data.frame" yields corrupt data frame (PR#13724)
Full_Name: Steven McKinney Version: 2.9.0 OS: Mac OS X 10.5.6 Submission from: (NULL) (142.103.207.10) A corrupt data frame can be constructed as follows: foo <- matrix(1:12, nrow = 3) bar <- data.frame(foo) bar$NewCol <- foo[foo[, 1] == 4, 4] bar lapply(bar, length) > foo <- matrix(1:12, nrow = 3) > bar <- data.frame(foo) > bar$NewCol <- foo[foo[, 1] == 4, 4]
2018 Apr 15
4
Adding a new conditional column to a list of dataframes
Hi all .., I have a list of 7000 dataframes with similar column headers and I wanted to add a new column to each dataframe based on a certain condition which is the same for all dataframes. When I extract one dataframe and apply my code it works very well as follows :- First suppose this is my first dataframe in the list > OneDF <- Mylist[[1]] > OneDF ID Pdate
2012 Oct 11
1
replacing ugly for loops
I have a couple of hundred American Community Survey Summary Files files containing rectangular arrays of data, mainly though not exclusively numeric. Each file is referred to as a sequence (henceforth "seq"). From these files I am trying to extract particular subsets (tables) consisting of a sets of columns. These tables are defined by three numbers (now in columns in a data frame):