Re: [R] Remove line from data file

2022-09-19 Thread avi.e.gross
bles which makes me wonder ... -Original Message- From: R-help On Behalf Of Parkhurst, David Sent: Sunday, September 18, 2022 8:49 AM To: CALUM POLWART Cc: R-help@r-project.org Subject: Re: [R] Remove line from data file Thank you for your reply. I meant from the dataframe

Re: [R] Remove line from data file

2022-09-19 Thread Parkhurst, David
mean by �value to delete�? Could that just be a row number? I was wanting to delete something like the 18th row in the dataframe? From: CALUM POLWART Date: Sunday, September 18, 2022 at 7:25 AM To: Parkhurst, David Cc: R-help@r-project.org Subject: Re: [R] Remove line from data file From

Re: [R] Remove line from data file

2022-09-18 Thread CALUM POLWART
ate: *Sunday, September 18, 2022 at 7:25 AM > *To: *Parkhurst, David > *Cc: *R-help@r-project.org > *Subject: *Re: [R] Remove line from data file > > From the file? Or the data frame once its loaded? > > > > What format is the file? CSV? > > > > Do you know t

Re: [R] Remove line from data file

2022-09-18 Thread CALUM POLWART
>From the file? Or the data frame once its loaded? What format is the file? CSV? Do you know the line that needs deleted? mydf <- read.csv("myfile.csv") mydf2 <- mydf[-columnName == "valuetodelete", ] # Note the - infront of column name # or perhaps columnName != "value to delete", ]

[R] Remove line from data file

2022-09-18 Thread Parkhurst, David
I’ve been retired since ‘06 and have forgotten most of R. Now I have a use for it. I’ve created a data file and need to delete one row from it. How do I do that? DFP (iPad) __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

Re: [R] Remove

2022-01-29 Thread Rui Barradas
Hello, This question is repeated [1]. [1] https://stat.ethz.ch/pipermail/r-help/2022-January/473663.html Rui Barradas Às 02:20 de 29/01/2022, Val escreveu: Hi All, I want remove row(s) that contains a character string in an integer column or a digit in a character column Sample data dat1

Re: [R] Remove all factor levels from an R dataframe

2020-11-10 Thread Eric Berger
Hi John, I was thinking that you created df1 in a way that set the 'year' column as a factor when this is not what you wanted to do. The data.frame() function takes an argument stringsAsFactors which controls this behavior. For R versions 3.6.3 or earlier, the default setting is

Re: [R] Remove all factor levels from an R dataframe

2020-11-10 Thread Jim Lemon
Sure John, df1<-df1[order(as.character(df1$year),decreasing=TRUE),] Jim On Tue, Nov 10, 2020 at 8:05 PM John wrote: > Thanks Jim. Can we do descending order? > > Jim Lemon 於 2020年11月10日 週二 下午4:56寫道: > >> Hi John, >> >> df1<-sapply(df1,as.character) >> >> Should do what you ask. The error

Re: [R] Remove all factor levels from an R dataframe

2020-11-10 Thread John
Thanks Jim. Can we do descending order? Jim Lemon 於 2020年11月10日 週二 下午4:56寫道: > Hi John, > > df1<-sapply(df1,as.character) > > Should do what you ask. The error message probably means that you should > do this: > > df1<-df1[order(as.character(df1$year)),] > > as "year" is the name of the first

Re: [R] Remove all factor levels from an R dataframe

2020-11-10 Thread Jim Lemon
Hi John, df1<-sapply(df1,as.character) Should do what you ask. The error message probably means that you should do this: df1<-df1[order(as.character(df1$year)),] as "year" is the name of the first column in df1, not a separate object. Jim On Tue, Nov 10, 2020 at 6:57 PM John wrote: > Hi, >

[R] Remove all factor levels from an R dataframe

2020-11-09 Thread John
Hi, I would like to sort the following simple dataframe by "year" (characters), but the factor structure prevents me from doing so. How can I remove the factor structure? Thanks! > df1 year country 4 2007 Asia; survey 5 2010 8 countries in E/SE Asia 6 2015

Re: [R] remove a row

2019-11-28 Thread Bert Gunter
Of course! Use regexec() and regmatches() > regmatches(dat$varx,regexec("(^[[:digit:]]{1,3})([[:alpha:]]{1,2})([[:digit:]]{1,5}$)",dat$varx)) [[1]] [1] "9F209" "9" "F" "209" [[2]] character(0) [[3]] [1] "2F250" "2" "F" "250" [[4]] character(0) [[5]] character(0) [[6]]

Re: [R] remove a row

2019-11-28 Thread Ashta
Thank you so much Bert. Is it possible to split the varx into three ( area code, region and the numeric part)as a separate variable On Thu, Nov 28, 2019 at 7:31 PM Bert Gunter wrote: > > Use regular expressions. > > See ?regexp and ?grep > > Using your example: > > >

Re: [R] remove a row

2019-11-28 Thread Bert Gunter
Use regular expressions. See ?regexp and ?grep Using your example: > grep("^[[:digit:]]{1,3}[[:alpha:]]{1,2}[[:digit:]]{1,5}$",dat$varx,value = TRUE) [1] "9F209" "2F250" "121FL50" Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and

[R] remove a row

2019-11-28 Thread Ashta
Hi all, I want to remove a row based on a condition in one of the variables from a data frame. When we split this string it should be composed of 3-2- 5 format (3 digits numeric, 2 characters and 5 digits numeric). Like area code -region-numeric. The max length of the area code should be 3, the

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-16 Thread Ana Marija
Hi Peter, Thank you so much!!! I will use complete linkage clustering because Mendelian Randomization function (https://cran.r-project.org/web/packages/MendelianRandomization/vignettes/Vignette_MR.pdf) I plan to use allows for correlations but not as high as 0.9 or more. I got 40 SNPs out of 246

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-15 Thread Peter Langfelder
Try hclust(as.dist(1-calc.rho), method = "average"). Peter On Fri, Nov 15, 2019 at 10:02 AM Ana Marija wrote: > > HI Peter, > > Thank you for getting back to me and shedding light on this. I see > your point, doing Jim's method: > > > keeprows<-apply(calc.rho,1,function(x) return(sum(x>0.8)<3))

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-15 Thread Jim Lemon
While the remedy for your dissatisfaction with my previous solution should be obvious, I will make it explicit. # that is rows containing at most one value > 0.8 # ignoring the diagonal keeprows<-apply(ro246,1,function(x) return(sum(x>0.8)<2)) ro246.lt.8<-ro246[keeprows,keeprows] Jim

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-15 Thread Ana Marija
if it is of any help my correlation matrix (calc.rho) was done here, under LDmatrix tab https://ldlink.nci.nih.gov/?tab=ldmatrix and dataset of 246 is bellow rs56192520 rs3764410 rs145984817 rs1807401 rs1807402 rs35350506 rs2089177 rs12325677 rs62064624 rs62064631 rs2349295 rs2174369 rs7218554

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-15 Thread Ana Marija
HI Peter, Thank you for getting back to me and shedding light on this. I see your point, doing Jim's method: > keeprows<-apply(calc.rho,1,function(x) return(sum(x>0.8)<3)) > ro246.lt.8<-calc.rho[keeprows,keeprows] > ro246.lt.8[ro246.lt.8 == 1] <- NA > (mmax <- max(abs(ro246.lt.8), na.rm=TRUE))

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Peter Langfelder
I suspect that you want to identify which variables are highly correlated, and then keep only "representative" variables, i.e., remove redundant ones. This is a bit of a risky procedure but I have done such things before as well sometimes to simplify large sets of highly related variables. If your

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Ana Marija
HI Jim, This: colnames(calc.jim)[colSums(abs(calc.jim)>0.8)<3] was the master take! Thank you so much!!! On Thu, Nov 14, 2019 at 3:39 PM Jim Lemon wrote: > > I thought you were going to trick us. What I think you are asking now > is how to get the variable names in the columns that have at

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Jim Lemon
I thought you were going to trick us. What I think you are asking now is how to get the variable names in the columns that have at most one _absolute_ value greater than 0.8. OK: # I'm not going to try to recreate your correlation matrix calc.jim<-matrix(runif(100,min=-1,max=1),nrow=10) for(i in

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Jim Lemon
Hi Ana, Rather than addressing the question of why you want to do this, Let's get make the question easier to answer: calc.rho<-matrix(c(0.903,0.268,0.327,0.327,0.327,0.582, 0.928,0.276,0.336,0.336,0.336,0.598, 0.975,0.309,0.371,0.371,0.371,0.638, 0.975,0.309,0.371,0.371,0.371,0.638,

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Ana Marija
what would be the approach to remove variable that has at least 2 correlation coefficients >0.8? this is the whole output of the head() > head(calc.rho) rs56192520 rs3764410 rs145984817 rs1807401 rs1807402 rs35350506 rs56192520 1.000 0.976 0.927 0.927 0.927

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Abby Spurdle
That's assuming your data was returned by head(). __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Abby Spurdle
> I basically want to remove all entries for pairs which have value in > between them (correlation calculated not in R, bit it is correlation, > r2) > so for example I would not keep: rs883504 because it has r2>0.8 for > all those rs... I'm still not sure what "remove all entries" means? In your

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Abby Spurdle
Sorry, but I don't understand your question. When I first looked at this, I thought it was a correlation (or covariance) matrix. e.g. > cor (quakes) > cov (quakes) However, your row and column variables are different, implying two different data sets. Also, some of the (correlation?)

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Ana Marija
I don't understand. I have to keep only pairs of variables with correlation less than 0.8 in order to proceed with some calculations On Thu, Nov 14, 2019 at 2:09 PM Bert Gunter wrote: > > Obvious advice: > > DON'T DO THIS! > > Bert Gunter > > "The trouble with having an open mind is that people

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Bert Gunter
Obvious advice: DON'T DO THIS! 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, Nov 14, 2019 at 10:50 AM Ana Marija wrote: > Hello, > > I have a data

[R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Ana Marija
Hello, I have a data frame like this (a matrix): head(calc.rho) rs9900318 rs8069906 rs9908521 rs9908336 rs9908870 rs9895995 rs56192520 0.903 0.268 0.327 0.327 0.327 0.582 rs3764410 0.928 0.276 0.336 0.336 0.336 0.598 rs145984817

Re: [R] Remove Even Number from A Vector

2019-03-03 Thread Duncan Murdoch
On 03/03/2019 3:44 a.m., Ivan Krylov wrote: Hi Darren, On Sat, 2 Mar 2019 22:27:55 + Darren Danyluk wrote: It sounds like she is working with the very basics of this software, and her task is to write the code which would result in the extraction of "odd" data from a dataset of

Re: [R] Remove Even Number from A Vector

2019-03-03 Thread Ivan Krylov
Hi Darren, On Sat, 2 Mar 2019 22:27:55 + Darren Danyluk wrote: > It sounds like she is working with the very basics of this software, > and her task is to write the code which would result in the > extraction of "odd" data from a dataset of restaurant sales. Not a native English speaker

Re: [R] Remove Even Number from A Vector

2019-03-02 Thread Jim Lemon
Hi Darren, You're probably looking for the %% (remainder) operator: x<-1:10 # get odd numbers x[as.logical(x%%2)] # get even numbers x[!(x%%2)] Jim On Sun, Mar 3, 2019 at 4:10 PM Darren Danyluk wrote: > > Hello, > > I found this email when looking for some help with R Studio. It's actually >

Re: [R] Remove Even Number from A Vector

2019-03-02 Thread Darren Danyluk
Hello, I found this email when looking for some help with R Studio. It's actually my daughter who is looking for help. It sounds like she is working with the very basics of this software, and her task is to write the code which would result in the extraction of "odd" data from a dataset of

Re: [R] Remove cases with -Inf from a data frame

2019-02-17 Thread Ek Esawi
This is a similar versions of other answers. df[apply(apply(df,2,is.finite),1,sum)==4,] BOL---EK On Sat, Feb 16, 2019 at 10:07 AM AbouEl-Makarim Aboueissa wrote: > > Dear All: good morning > > > I have a log-transformed data frame with some *-Inf* data values. > > *my question: *how to remove

Re: [R] Remove cases with -Inf from a data frame

2019-02-17 Thread AbouEl-Makarim Aboueissa
Dear Rui and All: thank you very much for your very helpful responses. with many thanks abou __ *AbouEl-Makarim Aboueissa, PhD* *Professor, Statistics and Data Science* *Graduate Coordinator* *Department of Mathematics and Statistics* *University of Southern Maine* On

Re: [R] Remove cases with -Inf from a data frame

2019-02-16 Thread Rui Barradas
Hello, An alternative, same dataset. df[apply(df, 1, function(x) all(is.finite(x))), ] Hope this helps, Rui Barradas Às 16:14 de 16/02/2019, Martin Møller Skarbiniks Pedersen escreveu: On Sat, 16 Feb 2019 at 16:07, AbouEl-Makarim Aboueissa < abouelmakarim1...@gmail.com> wrote: I have a

Re: [R] Remove cases with -Inf from a data frame

2019-02-16 Thread Bert Gunter
Sorry, that's function(x)all(is.finite(x) | is.na(x) ) of course. 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 Sat, Feb 16, 2019 at 8:25 AM Bert Gunter

Re: [R] Remove cases with -Inf from a data frame

2019-02-16 Thread Bert Gunter
Many ways. I assume you know that Inf and -Inf are (special) numeric values that can be treated like other numerics. i.e. > 1 == - Inf [1] FALSE So straightforward indexing (selection) would do it. But there is also ?is.infinite and ?is.finite, so apply(yourdat, 1, function(x)all(is.finite(x)))

Re: [R] Remove cases with -Inf from a data frame

2019-02-16 Thread Martin Møller Skarbiniks Pedersen
On Sat, 16 Feb 2019 at 16:07, AbouEl-Makarim Aboueissa < abouelmakarim1...@gmail.com> wrote: > > I have a log-transformed data frame with some *-Inf* data values. > > *my question: *how to remove all rows with *-Inf* data value from that data > frame? Hi, Here is a solution which uses apply.

Re: [R] Remove cases with -Inf from a data frame

2019-02-16 Thread Michael Dewey
Dear Abou Depends on exact details of your variables but ?is.finite Gives you the basic tool. On 16/02/2019 15:05, AbouEl-Makarim Aboueissa wrote: Dear All: good morning I have a log-transformed data frame with some *-Inf* data values. *my question: *how to remove all rows with *-Inf*

[R] Remove cases with -Inf from a data frame

2019-02-16 Thread AbouEl-Makarim Aboueissa
Dear All: good morning I have a log-transformed data frame with some *-Inf* data values. *my question: *how to remove all rows with *-Inf* data value from that data frame? with many thanks abou __ *AbouEl-Makarim Aboueissa, PhD* *Professor, Statistics and Data Science*

Re: [R] Remove specific rows from nested list of matrices

2018-11-08 Thread Ek Esawi
Thank you all, Bert, Jeff, Bill an Don. I realized I made a silly mistake in list indexing. Once I saw Bills’ suggestion and was able to wrap my head around indexing recursive lists, I resolved the problem. For future readers, here is the answers, even though the question may not have been clear.

Re: [R] Remove specific rows from nested list of matrices

2018-11-02 Thread MacQueen, Don via R-help
It appears that at the bottom of the nesting, so to speak, you have a character matrix. That is, the contents of the [[1]][[1]][[1]] element is a character matrix that, according to the row and column labels, has 4 rows and 5 columns. However, the matrix itself, as printed, has, apparently, 4

Re: [R] Remove specific rows from nested list of matrices

2018-11-02 Thread William Dunlap via R-help
Since you cannot show the data you have have to learn some R debugging techniques. Here is some data that look something like yours and I want to delete rows of character matrices whose first entry starts with a space. FF <- lapply(1:2,function(i)lapply(1:3, function(j) lapply(1:2, function(k)

Re: [R] Remove specific rows from nested list of matrices

2018-11-02 Thread Jeff Newmiller
A partial dput is no help at all. A complete dput of part of your data is much more likely to be helpful, but only if you see the same problem in it as you do in the full data set. As to private data... if you want data handling help in a public forum then you need to create a small set of

Re: [R] Remove specific rows from nested list of matrices

2018-11-02 Thread Ek Esawi
Thank you Jeff and Bert. I know i have to use dput add provide a reproducible example. The problem is that the output,is huge, has many nested lists, and the info is private. Here is the first line of dput(FF) if it helps: dput(FF) list(list(list(structure(c("12/30 12/30", "01/02 01/02", "01/02

Re: [R] Remove specific rows from nested list of matrices

2018-11-02 Thread Jeff Newmiller
Can you supply the output of dput(FF) ? On November 2, 2018 8:00:08 AM PDT, Ek Esawi wrote: >Hi All, > >I have a list that is made up of nested lists, as shown below. I want >to remove all rows in each sub-list that start with an empty space, >that’s the first entry of a row is blank; for

Re: [R] Remove specific rows from nested list of matrices

2018-11-02 Thread Bert Gunter
If you learn to use dput() to provide useful examples in your posts, you are more likely to receive useful help. It is rather difficult to make much sense of your messy text, though some brave soul(s) may try to help. Bert Gunter "The trouble with having an open mind is that people keep coming

[R] Remove specific rows from nested list of matrices

2018-11-02 Thread Ek Esawi
Hi All, I have a list that is made up of nested lists, as shown below. I want to remove all rows in each sub-list that start with an empty space, that’s the first entry of a row is blank; for example, on [[1]][[1]][[1]] Remove row 4,on [[1]][[1]][[3]] remove row 5, on [[1]][[2]][[1]] remove row

Re: [R] remove text from nested list

2018-10-25 Thread Ek Esawi
Thank you Bert and Peter. My apology for posting poor code. I cannot create a reproducible example of my data, but i hope the list indices as shown below helps you understand my question.. My regex pattern on my previous post works correctly because i tested it on a few sublists and it worked, but

Re: [R] remove text from nested list

2018-10-25 Thread William Dunlap via R-help
If your matrices are at various depths in the list, try rapply(). E.g., > L <- list( A = list( a1 = matrix(c("AAA","AB", "AAB","AC"),2,2), a2=c("AAx")), list(B = c("AAb1AAA","AAb2"))) > str(L) List of 2 $ A:List of 2 ..$ a1: chr [1:2, 1:2] "AAA" "AB" "AAB" "AC" ..$ a2: chr "AAx" $ :List

Re: [R] remove text from nested list

2018-10-25 Thread Bert Gunter
1. Please learn how to use dput() to provide examples to responders. There's not much we can do with a text printout (at least without some work that I don't care to do). 2. Do you know what mylist[[c(1,2,1)]] means? If not, read ?(Extract) and note in particular: "[[ can be applied recursively

Re: [R] remove text from nested list

2018-10-25 Thread Peter Langfelder
You should be more specific about what you want to replace and with what. The pattern you use, namely "[0-9][0-9]/[0-9[0-9].*com", does not (AFAICS) match any of the strings in your data, so don't be surprised that your commands do not change anything. If you have a correct pattern and

[R] remove text from nested list

2018-10-25 Thread Ek Esawi
Hi All— I have a list that contains multiple sub-lists and each sub-list contains multiple sub(sub-lists), each of the sub(sub-lists) is made up of matrices of text. I want to replace some of the text in some parts in the matrices on the list. I tried gsub and stringr, str_remove, but nothing

Re: [R] Remove plot axis values in dotplot graph

2018-09-11 Thread Jim Lemon
Hi Abou, Surprisingly you can't omit the x axis in dotchart. This hack will work: sink("dotchar_noax.R") sink() Edit the resulting file by joining the first two lines with the assignment symbol (<-), delete the two lines at the bottom and comment out the line "axis(1)".

[R] Remove plot axis values in dotplot graph

2018-09-11 Thread AbouEl-Makarim Aboueissa
Dear All: One more thing. I want to Remove the plot x-axis values in dotplot graph. I am trying to use xaxt = "n", but it seems NOT working. Also after removing the x-axis values, I want to use the command axis(1, at=0:16, cex.axis=1) to add x-axis values from 0 to 16, but it seems not working as

Re: [R] remove rows of a matrix by part of its row name

2018-05-22 Thread William Dunlap via R-help
I think it is simpler to use !grepl() instead of -grep() here, since subscripting with logicals works properly when there are no matches. Also, since mat is a matrix, add the argument drop=FALSE so the result is a matrix when all but one rows are omitted. E.g., > mat <- matrix(1:6, nrow=3,

Re: [R] remove rows of a matrix by part of its row name

2018-05-22 Thread Ahmed Serag
:16 PM To: Ahmed Serag; R-help@r-project.org Subject: Re: [R] remove rows of a matrix by part of its row name Hello, Please always cc the list. As for the question, yes, it does. If you want to remove just the ones with exactly 73.1 use the pattern grep("^73\\.1$", etc) Explanation: Beg

Re: [R] remove rows of a matrix by part of its row name

2018-05-22 Thread Rui Barradas
lp@r-project.org *Subject:* Re: [R] remove rows of a matrix by part of its row name Hello, Use grep to get the row indices and then subset with a *negative* index to remove those rows. rn <- scan(what = character(), text = " 70/556 71.1/280 72.1/556 72.1/343 73.1/390 73.1/556 ") mat &

Re: [R] remove rows of a matrix by part of its row name

2018-05-22 Thread Rui Barradas
Hello, Use grep to get the row indices and then subset with a *negative* index to remove those rows. rn <- scan(what = character(), text = " 70/556 71.1/280 72.1/556 72.1/343 73.1/390 73.1/556 ") mat <- matrix(rnorm(6*6), nrow = 6) row.names(mat) <- rn inx <- grep("73\\.", row.names(mat))

[R] remove rows of a matrix by part of its row name

2018-05-22 Thread Ahmed Serag
Dear R-experts, How can I remove a certain feature or observation by a part of its name. To be clear, I have a matrix with 766 observations as a rows. The row names are like this 70/556 71.1/280 72.1/556 72.1/343 73.1/390 73.1/556 Now I would like to remove all the rows that contain the text

Re: [R] Remove

2017-12-09 Thread Ashta
Thank you All !! Now, I have plenty of options to chose. On Sat, Dec 9, 2017 at 1:21 PM, William Dunlap wrote: > You could make numeric vectors, named by the group identifier, of the > contraints > and subscript it by group name: > >> DM <- read.table( text='GR x y > + A 25

Re: [R] Remove

2017-12-09 Thread William Dunlap via R-help
You could make numeric vectors, named by the group identifier, of the contraints and subscript it by group name: > DM <- read.table( text='GR x y + A 25 125 + A 23 135 + A 14 145 + A 35 230 + B 45 321 + B 47 512 + B 53 123 + B 55 451 + C 61 521 + C 68 235 + C 85 258 + C 80 654',header = TRUE,

Re: [R] Remove

2017-12-09 Thread David Winsemius
> On Dec 8, 2017, at 6:16 PM, David Winsemius wrote: > > >> On Dec 8, 2017, at 4:48 PM, Ashta wrote: >> >> Hi David, Ista and all, >> >> I have one related question Within one group I want to keep records >> conditionally. >> example within >>

Re: [R] Remove

2017-12-09 Thread Ek Esawi
HI-- How about this one. It produces the desired result. If you have more conditions, you can put them in a matrix/DF form and subset as suggested by one of the previous suggestion. DM[(DM$GR=="A"$x>=15$x<=30)|(DM$GR=="B"$x>=40$x<=50)|(DM $GR=="C"$x>=60$x<=70),] EK On Sat, Dec 9, 2017 at 5:00

Re: [R] Remove

2017-12-09 Thread Rui Barradas
Hello, Try the following. keep <- list(A = c(15, 30), B = c(40, 50), C = c(60, 75)) sp <- split(DM$x, DM$GR) inx <- unlist(lapply(seq_along(sp), function(i) keep[[i]][1] <= sp[[i]] & sp[[i]] <= keep[[i]][2])) DM[inx, ] # GR x y #1 A 25 125 #2 A 23 135 #5 B 45 321 #6 B 47 512 #9

Re: [R] Remove

2017-12-08 Thread Jeff Newmiller
In this case I cannot see an advantage to using dplyr over subset, other than if dplyr is your hammer then the problem will look like a nail, or if this is one step in a larger context where dplyr is more useful. Nor do I think this is a good use for mapply (or dplyr::group_by) because the

Re: [R] Remove

2017-12-08 Thread Michael Hannon
library(dplyr) DM <- read.table( text='GR x y A 25 125 A 23 135 . . . ) DM %>% filter((GR == "A" & (x >= 15) & (x <= 30)) | (GR == "B" & (x >= 40) & (x <= 50)) | (GR == "C" & (x >= 60) & (x <= 75))) On Fri, Dec 8, 2017 at 4:48 PM, Ashta

Re: [R] Remove

2017-12-08 Thread David Winsemius
> On Dec 8, 2017, at 4:48 PM, Ashta wrote: > > Hi David, Ista and all, > > I have one related question Within one group I want to keep records > conditionally. > example within > group A I want keep rows that have " x" values ranged between 15 and 30. > group B I want

Re: [R] Remove

2017-12-08 Thread Ashta
Hi David, Ista and all, I have one related question Within one group I want to keep records conditionally. example within group A I want keep rows that have " x" values ranged between 15 and 30. group B I want keep rows that have " x" values ranged between 40 and 50. group C I want keep

Re: [R] Remove

2017-12-06 Thread David Winsemius
> On Dec 6, 2017, at 4:27 PM, Ashta wrote: > > Thank you Ista! Worked fine. Here's another (possibly more direct in its logic?): DM[ !ave(DM$x, DM$GR, FUN= function(x) {!length(unique(x))==1}), ] GR x y 5 B 25 321 6 B 25 512 7 B 25 123 8 B 25 451 -- David > On

Re: [R] Remove

2017-12-06 Thread Ashta
Thank you Ista! Worked fine. On Wed, Dec 6, 2017 at 5:59 PM, Ista Zahn wrote: > Hi Ashta, > > There are many ways to do it. Here is one: > > vars <- sapply(split(DM$x, DM$GR), var) > DM[DM$GR %in% names(vars[vars > 0]), ] > > Best > Ista > > On Wed, Dec 6, 2017 at 6:58 PM,

Re: [R] Remove

2017-12-06 Thread Ista Zahn
Hi Ashta, There are many ways to do it. Here is one: vars <- sapply(split(DM$x, DM$GR), var) DM[DM$GR %in% names(vars[vars > 0]), ] Best Ista On Wed, Dec 6, 2017 at 6:58 PM, Ashta wrote: > Thank you Jeff, > > subset( DM, "B" != x ), this works if I know the group only. >

Re: [R] Remove

2017-12-06 Thread Ashta
Thank you Jeff, subset( DM, "B" != x ), this works if I know the group only. But if I don't know that group in this case "B", how do I identify group(s) that all elements of x have the same value? On Wed, Dec 6, 2017 at 5:48 PM, Jeff Newmiller wrote: > subset( DM, "B"

Re: [R] Remove

2017-12-06 Thread Jeff Newmiller
subset( DM, "B" != x ) This is covered in the Introduction to R document that comes with R. -- Sent from my phone. Please excuse my brevity. On December 6, 2017 3:21:12 PM PST, David Winsemius wrote: > >> On Dec 6, 2017, at 3:15 PM, Ashta wrote: >>

Re: [R] Remove

2017-12-06 Thread Ashta
Thank you David. This will not work. Tthis removes only duplicate records. DM[ !duplicated(DM$x) , ] My goal is to remove the group if all elements of x in that group have the same value. On Wed, Dec 6, 2017 at 5:21 PM, David Winsemius wrote: > >> On Dec 6, 2017, at

Re: [R] Remove

2017-12-06 Thread David Winsemius
> On Dec 6, 2017, at 3:15 PM, Ashta wrote: > > Hi all, > In a data set I have group(GR) and two variables x and y. I want to > remove a group that have the same record for the x variable in each > row. > > DM <- read.table( text='GR x y > A 25 125 > A 23 135 > A 14 145 >

[R] Remove

2017-12-06 Thread Ashta
Hi all, In a data set I have group(GR) and two variables x and y. I want to remove a group that have the same record for the x variable in each row. DM <- read.table( text='GR x y A 25 125 A 23 135 A 14 145 A 12 230 B 25 321 B 25 512 B 25 123 B 25 451 C 11 521 C 14 235 C 15 258 C 10

Re: [R] Remove spacing at the top and bottom of a plot

2017-09-24 Thread AbouEl-Makarim Aboueissa
sa > Sent: Sunday, September 24, 2017 3:59 PM > To: R mailing list <r-help@r-project.org> > Subject: [R] Remove spacing at the top and bottom of a plot > > Dear All: > > Is there is away to remove spacing at the top and the bottom of a plot? If > so, any help will be a

Re: [R] Remove spacing at the top and bottom of a plot

2017-09-24 Thread David L Carlson
Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of AbouEl-Makarim Aboueissa Sent: Sunday, September 24, 2017 3:59 PM To: R mailing list <r-help@r-project.org> Subject: [R] Remove spacing at the top and bottom of a plot Dear All: Is there is away to remove s

[R] Remove spacing at the top and bottom of a plot

2017-09-24 Thread AbouEl-Makarim Aboueissa
Dear All: Is there is away to remove spacing at the top and the bottom of a plot? If so, any help will be appreciated. Please use this code as an example: par(mfrow=c(1,2)) lizard <- c(6.2, 6.6, 7.1, 7.4, 7.6, 7.9, 8, 8.3, 8.4, 8.5, 8.6,8.8, 8.8, 9.1, 9.2, 9.4, 9.4, 9.7, 9.9, 10.2, 10.4,

Re: [R] remove quotes from matrix

2017-09-19 Thread greg holly
Hi Bert; I sincerely appreciate for this. When I follow your way I have got dimnames(dm) [[1]] NULL I think this is the reason why the matrix is being converted into a column vector. Regards, Greg On Tue, Sep 19, 2017 at 11:32 AM, Bert Gunter wrote: > Works fine for

Re: [R] remove quotes from matrix

2017-09-19 Thread David L Carlson
un...@gmail.com> Cc: r-help mailing list <r-help@r-project.org> Subject: Re: [R] remove quotes from matrix Dear all; Thanks. Here are the dput results as Duncan suggested. Regards, Greg structure(list(Sub_Pathways = structure(c(3L, 3L, 3L, 3L, 3L), .Label = c("Acetylated_Peptid

Re: [R] remove quotes from matrix

2017-09-19 Thread Bert Gunter
Works fine for me. What do you object to in the following? Calling the above df "d", > dm <- as.matrix(d) > dm Sub_PathwaysBMI_beta SAT_beta VAT_beta 1 "Alanine_and_Aspartate" " 0.23820" "-0.02409" " 0.94180" 2 "Alanine_and_Aspartate" "-0.31300" "-1.97510" "-2.22040" 3

Re: [R] remove quotes from matrix

2017-09-19 Thread greg holly
Dear all; Thanks. Here are the dput results as Duncan suggested. Regards, Greg structure(list(Sub_Pathways = structure(c(3L, 3L, 3L, 3L, 3L), .Label = c("Acetylated_Peptides", "Advanced_Glycation_End-product", "Alanine_and_Aspartate", "Aminosugar", "Ascorbate_and_Aldarate", "Carnitine",

Re: [R] remove quotes from matrix

2017-09-19 Thread Bert Gunter
Your claims are false -- or at least confused. > d <- data.frame(a = I(letters[1:3]), b = 1:3) ## the I() is to prevent automatic conversion to factor > d a b 1 a 1 2 b 2 3 c 3 > dm <- as.matrix(d) > dm a b [1,] "a" "1" [2,] "b" "2" [3,] "c" "3" > dimnames(dm) [[1]] NULL [[2]] [1] "a"

Re: [R] remove quotes from matrix

2017-09-19 Thread Jeff Newmiller
Greg, I think you should stop using noquote, because it is doing something that will not be useful to you for preparing your data for analysis. Please follow Duncan's advice and provide us with a sample of your data. Also, please set your email program to send plain text rather than HTML

Re: [R] remove quotes from matrix

2017-09-19 Thread greg holly
Hi Duncan and Bert; I do appreciate for your replies. I just figured out that after x1= noquotes(x) commend my 733*22 matrix returns into n*1 vector. Is there way to keep this as matrix with the dimension of 733*22? Regards, Greg On Tue, Sep 19, 2017 at 10:04 AM, Duncan Murdoch

Re: [R] remove quotes from matrix

2017-09-19 Thread Duncan Murdoch
On 19/09/2017 9:47 AM, greg holly wrote: Hi all; I have data at 734*22 dimensions with rows and columns names are non-numeric.When I convert this data into matrix then all values show up with quotes. Then when I use x1= noquotes(x) to remove the quotes from the matrix then non-numeric row names

[R] remove quotes from matrix

2017-09-19 Thread greg holly
Hi all; I have data at 734*22 dimensions with rows and columns names are non-numeric.When I convert this data into matrix then all values show up with quotes. Then when I use x1= noquotes(x) to remove the quotes from the matrix then non-numeric row names remain all other values in matrix

Re: [R] Remove attribute from netcdf4 object

2017-08-02 Thread Marc Girondot
Le 02/08/2017 à 12:03, raphael.fel...@agroscope.admin.ch a écrit : > Dear all > > For a model I need to combine several netCDF files into one (which works > fine). For better overview I'd like to delete/remove some of the attributes. > Is there a simple way doing this? > > I'm using the package

Re: [R] Remove attribute from netcdf4 object

2017-08-02 Thread raphael.felber
<raphael.fel...@agroscope.admin.ch> Betreff: Re: AW: [R] Remove attribute from netcdf4 object ok. Sorry, I didn't understood good. I don't think you can do it in ncdf4 functions. The only solution would be to open it in RNetCDF, delete the attribute, save it and then open it in ncdf4. Marc Le 02/0

Re: [R] Remove attribute from netcdf4 object

2017-08-02 Thread raphael.felber
<raphael.fel...@agroscope.admin.ch>; r-help@r-project.org Betreff: Re: [R] Remove attribute from netcdf4 object Le 02/08/2017 à 12:03, raphael.fel...@agroscope.admin.ch<mailto:raphael.fel...@agroscope.admin.ch> a écrit : Dear all For a model I need to combine several netCDF files int

[R] Remove attribute from netcdf4 object

2017-08-02 Thread raphael.felber
Dear all For a model I need to combine several netCDF files into one (which works fine). For better overview I'd like to delete/remove some of the attributes. Is there a simple way doing this? I'm using the package netcdf4, which creates an object of class(nc) = "ncdf4". It seems that for

Re: [R] remove

2017-06-11 Thread Jeff Newmiller
The usual way I filter is: KL$Dt <- as.Date( KL$date, format='%d-%m-%y' ) KL2 <- KL[ !is.na( KL$Dt ), ] -- Sent from my phone. Please excuse my brevity. On June 10, 2017 10:17:52 PM PDT, Jeff Newmiller wrote: >You are using a slash in your format string to separate

Re: [R] remove

2017-06-10 Thread Bert Gunter
Also ?ifelse rather than if() I think. Cheers, 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 Sat, Jun 10, 2017 at 10:17 PM, Jeff Newmiller

Re: [R] remove

2017-06-10 Thread Jeff Newmiller
You are using a slash in your format string to separate sub-fields but your data uses a dash. -- Sent from my phone. Please excuse my brevity. On June 10, 2017 8:18:37 PM PDT, Val wrote: >Hi all, >I have a date issue and would appreciate any help. > >I am reading a field

[R] remove

2017-06-10 Thread Val
Hi all, I have a date issue and would appreciate any help. I am reading a field data and n one of the columns I am expecting a date but has non date values such as character and empty. space. Here is a sample of my data. KL <- read.table(header=TRUE, text='ID date 711 Dead 712 Uknown 713

  1   2   3   4   5   6   7   >