[R] Subtraction loop
I have a data frame with 2 columns, one for day and one for average. The day starts at 97 all the way to 279. I want to subtract day 98 average- day 97 average, then day99 average -day 98 average and so on down my list, creating another column with the subtracted results. I have: Day DailyAverage 1970.6076782 2980.7121478 3990.8059347 4 1000.9545806 5 1011.0589791 6 1021.1335981 7 1031.2676922 8 1041.4429847 9 1051.6477266 10 1061.7970784 etc. with values to day 279 I'm guessing I need to create some kind of loop for this, but I am unsure as to how to do this. Any help is greatly appreciated. Thanks, Emilija __ R-help@r-project.org mailing list 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] Calculating a daily average
I have a set of data with 12 readings for temperature per day, with 180 days. I want to find the average temperature of each day. I am able to do this one by one, but with that many days to calculate the average for, it will get very long. I'm sure there is a faster way to do this, I just don't know how. What i have so far is: av1 <- subset(ER9r, Day == 98, select = c (Depth1j:Depth0.75j)) av1 <- mean(av1 [av1>0]) av2 <- subset(ER9r, Day == 99, select = c (Depth1j:Depth0.75j)) av2 <- mean(av2 [av2>0]) av3 <- subset(ER9r, Day == 100, select = c (Depth1j:Depth0.75j)) av3 <- mean(av3 [av3>0]) av4 <- subset(ER9r, Day == 101, select = c (Depth1j:Depth0.75j)) av4 <- mean(av4 [av4>0]) av5 <- subset(ER9r, Day == 102, select = c (Depth1j:Depth0.75j)) av5 <- mean(av5 [av5>0]) Depth<- c("SML") Day<- c(98, 99, 100, 101, 102) Average<- c(av1, av2, av3, av4, av5) chlsummaryER9 <- data.frame (Depth, Day, Average) chlsummaryER9 Any ideas on how to do this in less steps? Thanks, Emilija __ R-help@r-project.org mailing list 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] 3D ncdf file
Hello, I have an ncdf file with different variables for dimensions and dates where the dimensions are as follows, where X=i and Y=j creating a 88 by 188 set of cells. For each cell there are 12 readings for DO taken at 2 hour intervals and recoded by according to the Julian calendar under the ordinal dates variable. DO: [2280x188x85] DX: [188x85] DY: [188x85] X: [85x1] Y: [188x1] Ordinal_Dates: [2280x1] T: [2280x1] So far, I have set up each variable as follows, and I don?t know how to work with the 3D DO variable which contains 12 daily values per day setwd ("C:/Documents and Settings/Desktop/R") library(ncdf) profile1 <- open.ncdf("2005r1_v3_Ct=500_lerie_out_bot.nc", header=FALSE) name1<-get.var.ncdf( profile1, "DO") name2<-get.var.ncdf( profile1, "DX") name3<-get.var.ncdf( profile1, "DY") name4<-get.var.ncdf( profile1, "X") name5<-get.var.ncdf( profile1, "Y") name6<-get.var.ncdf( profile1, "Ordinal_Dates") name7<-get.var.ncdf( profile1, "T") I want to set a threshold, and calculate how many days have an average of DO greater then my threshold, and also what the daily averages of DO are Any help is appreciated! Emilija __ R-help@r-project.org mailing list 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 skip negative values when calculating average
I have a data frame 10 by 12 with positive and negative numbers. I want to select only the positive numbers and find the average. This calculates the average of everything: av5 <- subset(ER9r, Day == 253, select = c (Depth1j:Depth0.75j) av5 <- mean(av5) I need something along the lines of "select" av5>0 Thanks in advance! Emilija __ R-help@r-project.org mailing list 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] if negative value, make zero
I have a data frame with both positive and negative values, and I want to make all the negative values equal zero, so i can eventually take an average. I've tried temp2 <- ifelse(tempr<0, 0, tempr) but it doesn't seem to work. Any suggestions? Thanks! __ R-help@r-project.org mailing list 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 calculate mean of means
I have 3 columns of numbers, and i want to find the mean of each separately, and then the mean of all of the means. ive tried: av3daysB<- mean(mean(avr1), mean(avr2), mean(avr3)) av3daysB but it only gives me the mean of the first column (avr1) Any suggestions? Thanks, Emilija __ R-help@r-project.org mailing list 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] Repeating Name for Rows
Hello, I have a large data frame (47:2186), where i want to label every 12th row. This command works, Day <-rep(97:278, each = 12) However i need 97 to only labeled 11 rows and then from 98:278 can be labeled every 12 times. Thanks! __ R-help@r-project.org mailing list 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] Adding a row at top of dataframe
I have a large data frame 48:2185 with different numbers. I would like to add only one row at the very top of my data frame with 0's or NA's. I don't know which approach to use. Should i create 2 different data frames and merge them? Ive also tried the rbind command with no luck. I would appreciate some help to achieve what I'm trying to create. Thanks! __ R-help@r-project.org mailing list 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] Adding name to nth row
Hello, I have a data frame with many rows, and I want to create a column with a name only at every 12th row, starting from 97 to 278. Thanks in advance! __ R-help@r-project.org mailing list 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.