[R] How to fix this problem
I have a matrix, KD6, and I�m trying to get a correlation matrix from it. When I enter cor(KD6), I get the message �Error in cor(KD6) : 'x' must be numeric�. Here are some early lines from KD6: Flow E..coliTNSRP TPTSS 1 38.82,4201.65300 0.0270 0.0630 66.80 2 133.02,4201.39400 0.0670 0.1360 6.80 3 86.2 101.73400 0.0700 0.1720 97.30 4 4.85,3900.40400 0.0060 0.0280 8.50 5 0.32,4900.45800 0.0050 0.0430 19.75 6 0.0 1860.51200 0.0040 0.0470 12.00 7 11.19,8351.25500 0.0660 0.1450 12.20 Why are these not numeric? There are some NAs later in the matrix, but I get this same error if I ask for cor(KD6[1:39,]) to leave out the lines with NAs. Are they a problem anyway? [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] Odd result
With help from several people, I used file.choose() to get my file name, and read.csv() to read in the file as KurtzData. Then when I print KurtzData, the last several lines look like this: 39 5/31/22 16.0 3411.75525 0.0201 0.0214 7.00 40 6/28/22 2:00 PM 0.0 2150.67950 0.0156 0.0294 NA 41 7/25/22 11:00 AM 11.9 1943.5NA NA 0.0500 7.80 42 8/31/22 0220.5NA NA 0.0700 30.50 43 9/28/22 0.067 10.9NA NA 0.0700 10.20 44 10/26/22 0.086 237NA NA 0.1550 45.00 45 1/12/23 1:00 PM 36.2624196NA NA 0.7500 283.50 46 2/14/23 1:00 PM 20.71 55NA NA 0.0500 2.40 47 NA NA NA NA 48 NA NA NA NA 49 NA NA NA NA Then the NA�s go down to one numbered 973. Where did those extras likely come from, and how do I get rid of them? I assume I need to get rid of all the lines after #46, to do calculations and graphics, no? David [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] How to import an excel data file
I know I should save it as a .csv file, which I have done. I�m told I should use the read_excel() function from the readxl package. My question is, how do I express the location of the file. The file is named KurtzData.csv. Its location in my Mac files is DFPfiles/ae/FriendsMonroe/KurtzData.csv How exactly---What �, etc.---do I type with its name in the read_excel() function? It�s been a long time since I�ve used R. Thanks for any help. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Need help plotting
I like the looks of what you are doing here. However, this from my system: > library(chron) Error in library(chron) : there is no package called �chron� How can I get chron? Also, IU�s tech support told me yesterday that if I responded to a message that came as plain text, my response would go out as plain text. Is that true for this response, or is it in HTML? From: Rui Barradas Date: Tuesday, September 20, 2022 at 4:52 AM To: Jim Lemon , Parkhurst, David , r-help mailing list Subject: Re: [R] Need help plotting Hello, Now with data, here are base R and ggplot2 plots. b <- read.table(text= "Dtime DNO2 DVOC Dpm10Dpm2.5 Dpm1 Mtime MNO2 MVOCMpm10 Mpm2.5 Mpm1 18:00 28 164 81.34773 24.695435 14 18:00 19 151 3.00 21 18:01 27 163 74.44034 23.751198 14 18:01 20 148 3.00 21 18:02 30 160 72.21975 22.463129 13 18:02 19 150 3.00 21", header=TRUE,stringsAsFactors=FALSE) # This base R plot needs package chron library(chron) [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Converting time format
Thank you. From: Rui Barradas Date: Monday, September 19, 2022 at 1:28 PM To: Parkhurst, David , R-help@r-project.org Subject: Re: [R] Converting time format Hello, I will run the examples below with the following data: x <- c("12:00", "12:15", "12:30", "12:45", "13:00", "13:15", "13:30", "13:45", "14:00", "14:15", "14:30", "14:45", "15:00", "15:15", "15:30", "15:45", "16:00", "16:15", "16:30", "16:45", "17:00", "17:15", "17:30", "17:45", "18:00") b <- data.frame(time = x, myvar = sin(2*pi*seq_along(x)/length(x))) Are they are saying is true, the vector b$myvar is a character vector and that's what is being displayed. In what follows I will first give examples of base graphics. The times are first coerced to a proper time class with package chron. library(chron) b$time <- as.times(b$time) # see ?plot.default for the meaning of # argument 'type' plot(myvar ~ time, b) plot(myvar ~ time, b, type = "l") plot(myvar ~ time, b, type = "b") With ggplot2, there is no need to load a date/time class package, R can do it with ?as.POSXct but the labels are datetime_breaks and datetime_labels. library(ggplot2) b |> dplyr::mutate(time = paste(Sys.Date(), time), time = as.POSIXct(time)) |> ggplot(aes(time, myvar)) + geom_line() + geom_point() + scale_x_datetime(date_breaks = "1 hour", date_labels = "%H:%M") + theme_bw() Hope this helps, Rui Barradas �s 01:56 de 19/09/2022, Parkhurst, David escreveu: > I have a dataframe obtained using read.csv from an excel file. Its first > column is times, running from 18:00 to 19:30. If I want to plot other > columns against time, do I need to convert those somehow, and how would I do > that? > > If I run plot(b$time,b$myvar) I get a decent plot, but a friend suggests that > R is just treating those numbers as text, and putting them in alphabetical > order. True? > >[[alternative HTML version deleted]] > > __ > 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 commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Converting time format
Thank you. I�ll see what I can do with that. From: Rui Barradas Date: Monday, September 19, 2022 at 1:28 PM To: Parkhurst, David , r-help@r-project.org Subject: Re: [R] Converting time format Hello, I will run the examples below with the following data: x <- c("12:00", "12:15", "12:30", "12:45", "13:00", "13:15", "13:30", "13:45", "14:00", "14:15", "14:30", "14:45", "15:00", "15:15", "15:30", "15:45", "16:00", "16:15", "16:30", "16:45", "17:00", "17:15", "17:30", "17:45", "18:00") b <- data.frame(time = x, myvar = sin(2*pi*seq_along(x)/length(x))) Are they are saying is true, the vector b$myvar is a character vector and that's what is being displayed. In what follows I will first give examples of base graphics. The times are first coerced to a proper time class with package chron. library(chron) b$time <- as.times(b$time) # see ?plot.default for the meaning of # argument 'type' plot(myvar ~ time, b) plot(myvar ~ time, b, type = "l") plot(myvar ~ time, b, type = "b") With ggplot2, there is no need to load a date/time class package, R can do it with ?as.POSXct but the labels are datetime_breaks and datetime_labels. library(ggplot2) b |> dplyr::mutate(time = paste(Sys.Date(), time), time = as.POSIXct(time)) |> ggplot(aes(time, myvar)) + geom_line() + geom_point() + scale_x_datetime(date_breaks = "1 hour", date_labels = "%H:%M") + theme_bw() Hope this helps, Rui Barradas �s 01:56 de 19/09/2022, Parkhurst, David escreveu: > I have a dataframe obtained using read.csv from an excel file. Its first > column is times, running from 18:00 to 19:30. If I want to plot other > columns against time, do I need to convert those somehow, and how would I do > that? > > If I run plot(b$time,b$myvar) I get a decent plot, but a friend suggests that > R is just treating those numbers as text, and putting them in alphabetical > order. True? > >[[alternative HTML version deleted]] > > __ > 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 commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Need help plotting
Thank you. DFP (iPad) > On Sep 19, 2022, at 8:15 AM, Ebert,Timothy Aaron wrote: > > My version of this email has a bunch of ? that I do not know how to > interpret. Emails to this group need to be in plain text. HTML content is > deleted or converted and impossible or at least difficult to interpret. > > Do not share confidential data. Please change some numbers or variable names > and share that. > If this helps: > 1) Make sure your time variable is a datetime object. > 2) At least in ggplot it should now behave as expected. > ggplot(df, aes(y=NO2, x=datetime)) + geom_point() > > That will be a start as a scatterplot, but the graph can be customized or > changed if scatterplot was not desired. > > Tim > > -Original Message- > From: R-help On Behalf Of Parkhurst, David > Sent: Sunday, September 18, 2022 4:27 PM > To: r-help@r-project.org > Subject: [R] Need help plotting > > [External Email] > > I�ve been retired since �06 and have forgotten most of R. Now I have a use > for it, with some data from Bloomington�s Environmental Commission. > > I have a dataframe (obtained from read.csv) that contains numerous columns, > including time (in Excel�s 18:00 format), and DNO2, and MNO2 from two air > quality instruments. > > I�d like a plot of both the NO2 measurements against time. I be happy to use > either ordinary R plots or ggplot2 ones, if that would be a better way. I�d > much appreciate help. > >[[alternative HTML version deleted]] > __ 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 commented, minimal, self-contained, reproducible code.
[R] Converting time format
I have a dataframe obtained using read.csv from an excel file. Its first column is times, running from 18:00 to 19:30. If I want to plot other columns against time, do I need to convert those somehow, and how would I do that? If I run plot(b$time,b$myvar) I get a decent plot, but a friend suggests that R is just treating those numbers as text, and putting them in alphabetical order. True? [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] Need help plotting
I�ve been retired since �06 and have forgotten most of R. Now I have a use for it, with some data from Bloomington�s Environmental Commission. I have a dataframe (obtained from read.csv) that contains numerous columns, including time (in Excel�s 18:00 format), and DNO2, and MNO2 from two air quality instruments. I�d like a plot of both the NO2 measurements against time. I be happy to use either ordinary R plots or ggplot2 ones, if that would be a better way. I�d much appreciate help. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Remove line from data file
Thank you for your reply. I meant from the dataframe, but that�s one of the terms I had forgotten. I created that from read.csv, the csv file coming from Excel. Last night I went ahead and made the change(s) using Excel. For future reference, when I look at your solutions below, what do you 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 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", ] write.csv(mydf2, "mydeletedfile.csv") On Sun, 18 Sep 2022, 10:33 Parkhurst, David, mailto:parkh...@indiana.edu>> wrote: 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<mailto: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 commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] Remove line from data file
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 https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Can't save files from the Source pane of R Studio
I�m just starting to learn and use R Studio in my Mac. Now I find if I type lines in what I think is called the source pane, and use Save as from the menu, nothing gets saved. That�s true if I add the extension .R or the extension .txt. If I try reopen the file in an empty source pane, it�s empty. And even if I open the file in a text editor, it�s blank. How can I save my work from R Studio? [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] [External] Concatenation?
Thank you. From: Richard M. Heiberger Date: Wednesday, February 17, 2021 at 4:21 PM To: Parkhurst, David , r-help@r-project.org Subject: Re: [External] [R] Concatenation? > paste(c("A","B","C"), c(1,2,3), sep="") [1] "A1" "B2" "C3" in your example paste(site, depth, sep="") ____ From: R-help on behalf of Parkhurst, David Sent: Wednesday, February 17, 2021 4:09 PM To: r-help@r-project.org Subject: [External] [R] Concatenation? If I have a vector of site abbreviations and a vector of depths in those water bodies, is there a simple way in R to combine them to make a third vector? Examples: sitedepth desired MU 0 MU0 MU 1 MU1 MU 2 MU2 MC 0 MC0 MC 1 MC1 MC 2 MC2 The dataset has many more lines than this. I can see how to do this with lots of if statements, but does R have magic that can make it happen easily? I guess this would be called concatenation. __ 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 commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] Concatenation?
If I have a vector of site abbreviations and a vector of depths in those water bodies, is there a simple way in R to combine them to make a third vector? Examples: sitedepth desired MU 0 MU0 MU 1 MU1 MU 2 MU2 MC 0 MC0 MC 1 MC1 MC 2 MC2 The dataset has many more lines than this. I can see how to do this with lots of if statements, but does R have magic that can make it happen easily? I guess this would be called concatenation. __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Need help using lattice
Thanks. What editor do you use? I'm working in a Mac, if that makes a difference. From: Gerrit Draisma Date: Tuesday, February 9, 2021 at 5:10 PM To: Parkhurst, David F. Cc: r-help@r-project.org Subject: Re: [R] Need help using lattice Ha David, I do not know. It must be that your AprtoDec object is different from month.abb. Anyhow it should contain the labels for all twelve months! If I copy your command in an interactive session I just get the message that AprtoDec is not defined. I understand that you type the commands interactively in an R session? I usually prefer using an editor to write the program, and execute with a > source("dotplot.R",echo=TRUE) command. I like an editor with syntax highlighting and shows matching brackets. I have attached my dotplot.R to this mail. Gerrit __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Need help using lattice
When I enter your line: df <- expand.grid(site=c("een","twee","drie","vier","vijf"), month=factor(3:12,levels=1:12, labels=month.abb, ordered=TRUE)) I get + signs in front of month and label, as expected, and it follows with < When I convert that to use my own variable names to this: df <- expand.grid(site=c("CrCr","NFSC","MFSC","SFSC","LMO","MCE","MUE","MLE"), monames=factor(3:12, levels=1:12, labels=AprToDec, ordered=TRUE)) I get + signs in front of monames and labels, again as expected, but then it gives me another + sign. And if I try to add another ), it keeps giving me + signs. What is happening here? From: Gerrit Draisma Date: Tuesday, February 9, 2021 at 6:14 AM To: Parkhurst, David F. Cc: r-help@r-project.org Subject: Re: [R] Need help using lattice Ha David, Thanks for your reply. For your last question, you have to change month into an ordered factor variable: library(lattice) df <- expand.grid(site=c("een","twee","drie","vier","vijf"), month=factor(3:12,levels=1:12, labels=month.abb, ordered=TRUE)) df$conc <- rnorm(dim(df)[1]) dotplot(month~conc|site,data=df) HTH, Gerrit Op 08-02-2021 om 21:04 schreef Parkhurst, David F.: > That worked nicely; thanks again. Here’s what I used for our data: > > library(lattice) > > df <- > expand.grid(site=c("CrCr","NFSC","MFSC","SFSC","LMO","MCE","MUE","MLE","MoCe"),months=1:9) > > dotplot(months~conc | site, data=df) > > The result is attached. Is there a way to replace the month numbers on > the y axes with the names Apr-Dec? > > David > __ 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 commented, minimal, self-contained, reproducible code.
Re: [R] Need help using lattice
Thank you. From: Gerrit Draisma Date: Tuesday, February 9, 2021 at 6:14 AM To: Parkhurst, David F. Cc: r-help@r-project.org Subject: Re: [R] Need help using lattice Ha David, Thanks for your reply. For your last question, you have to change month into an ordered factor variable: library(lattice) df <- expand.grid(site=c("een","twee","drie","vier","vijf"), month=factor(3:12,levels=1:12, labels=month.abb, ordered=TRUE)) df$conc <- rnorm(dim(df)[1]) dotplot(month~conc|site,data=df) HTH, Gerrit Op 08-02-2021 om 21:04 schreef Parkhurst, David F.: > That worked nicely; thanks again. Here�s what I used for our data: > > library(lattice) > > df <- > expand.grid(site=c("CrCr","NFSC","MFSC","SFSC","LMO","MCE","MUE","MLE","MoCe"),months=1:9) > > dotplot(months~conc | site, data=df) > > The result is attached. Is there a way to replace the month numbers on > the y axes with the names Apr-Dec? > > David > [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.
[R] Need help using lattice
I have a dataframe comprising a vector of E. coli concentrations, a vector of months when the samples were taken, and a vector of sampled sites. I�d like to produce a lattice with sites along the horizontal axis, and months on the vertical. Each site-month box would then contain concentrations ranging along its x axis. I think this would use dotchart (or possibly stripchart) in the lattice. I�ve been reading the lattice and xyplot documents and I�m overwhelmed. I�d appreciate help in how to write the call. David [[alternative HTML version deleted]] __ 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 commented, minimal, self-contained, reproducible code.