search for: mydata

Displaying 20 results from an estimated 448 matches for "mydata".

2010 Apr 05
2
find the "next non-NA" value within each row of a data-frame
#I wish to find the "next non-NA" value within each row of a data-frame. #e.g. I have a data frame mydata. Rows 1, 2 & 3 have soem NA values. mydata <- data.frame(matrix(seq(20*6), 20, 6)) mydata[1,3:5] <-  NA mydata[2,2:3] <-  NA mydata[2,5] <-  NA mydata[3,6] <-  NA mydata[1:3,] #this loop accomplishes the task; I am tryign toi learn a "better" way for(i in (ncol(mydat...
2007 Jun 15
8
model.frame: how does one use it?
...orting arguments, in particular ''weights''. A simple contrived example is ----------------------------------------------------------------------------- library(rpart) ## using data from help(rpart), set up simple example myformula <- formula(Kyphosis ~ Age + Number + Start) mydata <- kyphosis myweight <- abs(rnorm(nrow(mydata))) goodFunction <- function(mydata, myformula, myweight) { hyp <- rpart(myformula, data=mydata, weights=myweight, method="class") prev <- hyp } goodFunction(mydata, myformula, myweight) cat("Ok\n") ## now remove...
2009 Dec 01
3
Stripchart: way to get different colour for each group
Hi, Is there a way to get different colour based on group when plotting stripchart? mydata <- data.frame(val1 = c(1.1, 3.2, 4.1, 2.5, 6.2, 5.3, 4.5, 2.2, 4.7, 2.7), val2 = c(4.2, 5.3, 3.4, 2.6, 5.3, 6.2, 7.7, 4.8, 3.4, 2.1), group = rep(0:1, 5)) mydata.stack <- stack(mydata, select=-group) stripchart(values ~ ind, data=mydata.stack, vertical=T, at=c(1...
2009 Apr 07
6
newbie query: simple crosstabs
...aying around with various table tools, trying to construct a fairly simple cross-tab. It shouldn''t be hard, but for some reason it turning out to be (for me). If I want to see how many men and how many women agree with a agree/disagree question (coded 1,0), I can do this: >attach(mydata) >mytable <- table(male, q1.bin) # gender and a binary response variable >prop.table(mytable, 1) # row percentages q1.bin male 0 1 0 0.3988 0.6012 1 0.2879 0.7121 I can repeat that for each of the items I want gender breakdowns for (q2, q3, q4 ....). But what I real...
2007 Jun 21
11
Overlaying lattice graphs (continued)
...d overlaying multiple plots. Deepayan kindly indicated to me the panel.superposition command which worked perfectly in the context of the example I gave. I''d like to go a little bit further on this topic using a more complex dataset structure (actually the one I want to work on). >mydata Plot Model Individuals Time Observed Predicted 1 1 A 1 0.05 10 10.2 2 1 A 1 0.10 20 19.5 etc... 10 1 B 1...
2008 May 16
1
xyplot: subscripts, groups and subset
I have stumbled across something in the Lattice package that is vexing me. Consider the code below: __________________________________________________________ library(lattice) myData <- expand.grid(sub = factor(1:16), time = 1:10) myData$observed <- rnorm(nrow(myData)) myData$fitted <- with(myData, ave(observed, sub, FUN = mean)) myData$event.time <- with(myData, ave(observed, sub, FUN = function(.x) 10 * runif(1))) myData <- myData[order(myData$sub, myData$tim...
2013 Jun 10
2
padding specific missing values with NA to allow cbind
Dear list Getting very frustrated with this simple-looking problem > m1 <- lm(x~y, data=mydata) > outliers <- abs(stdres(m1))>2 > plot(x~y, data=mydata) I would like to plot a simple x,y scatter plot with labels giving custom information displayed for the outliers only, i.e. I would like to define a column mydata$labels for the mydata dataframe so that the command > text(myd...
2004 Mar 26
1
Mahalanobis
Dear all Why isn''it possible to calculate Mahalanobis distances with R for a matrix with 1 row (observations) more than the number of columns (variables)? > mydata <- matrix(runif(12,-5,5), 4, 3) > mahalanobis(x=mydata, center=apply(mydata,2,mean), cov=var(mydata)) [1] 2.25 2.25 2.25 2.25 > mydata <- matrix(runif(420,-5,5), 21, 20) > mahalanobis(x=mydata, center=apply(mydata,2,mean), cov=var(mydata)) [1] 19.04762 19.04762 19.04762 19.04762 19...
2017 Oct 16
1
Download data from NASA for multiple locations - RCurl
..., 12, 13), temp = substr(df, 21, 27)) data_frames[[i]] <- df } What I have been have been having trouble is adding the following information from the cities file (100 cities) for each of the downloaded data files. I would like to do the following but automatically: ### mydata$city <- rep(cities[1,1], nrow(mydata)) mydata$state <- rep(cities[1,2], nrow(mydata)) mydata$lon <- rep(cities[1,3], nrow(mydata)) mydata$lat <- rep(cities[1,4], nrow(mydata)) ### The information for cities look like this: ### cities <- dput(droplevels(head(cities, 5))) structure(...
2018 May 20
3
Loop Function to Create Multiple Scatterplots
...unction out 18 times to make the 18 graphs. My code is below and csv file is attached. *Code* wd <- setwd("~/Dropbox/Steve/SM Research Projects/Allen Brain Bank Project/Allen Brain Bank Inflammatory Markers Project Matlab:R/Other/2018 Tests") list.files(wd) mydata <- read.csv("Glutamate.Genes.V1.csv") mydata plot(mydata$Age..weeks.post.conception., mydata$GluA1..GRIA1..Expression) plot(mydata$Age..weeks.post.conception., mydata$GluA2..GluR2.GRIA2..Expression), etc Thank you for your time and help. Regards, Steven
2011 Dec 11
6
multiple comparison of interaction of ANCOVA
Hi there, The following data is obtained from a long-term experiments. > mydata <- read.table(textConnection(" + y year Trt + 9.37 1993 A + 8.21 1995 A + 8.11 1999 A + 7.22 2007 A + 7.81 2010 A + 10.85 1993 B + 12.83 1995 B + 13.21 1999 B + 13.70 2007 B + 15.15 2010 B + 5.69 1993 C + 5.76 1995 C...
2009 Dec 10
2
Help with beanplot fromatting
...plot) then D and E (as full beans). I assume there is some way to do this, but searching the help archives, I haven''t been able to find it. I would also like to thank all of you, for your answers to others questions, I have been gathering many useful tips. # example library(beanplot) mydata <- data.frame(tank = rep(c("A","B","C","D","E"), c(100,100,50,100,100)), group = rep(c("grp1", "grp2")), val = rnorm(450)) mydata$grouprep <- paste( mydata$tank, mydata$group) mydata$grouprep <-with(mydata, ifelse((tan...
2013 Feb 17
2
How to findout the name of a dataframe
Let''say we have a dataframe mydata with column v1. If mydata$v1 is passed to a function, is there way, then, to extract the name of the dataframe? What I now do is passing the name of the dataframe to the funcion, so passing two parameters. Maybe with mydata$v1 it is not possible, but with mydata[''v1''] or mydata[,&...
2006 Aug 23
4
glm inside one self-defined function
Hi list, I''ve searched in R-help and found some related discussions but still could not understand this type of error. My own function is pretty complex, so I would not put it here, but the basic algorithm is like this: myfun<-function(k){ mydata<-...#by someway I create a data frame mymodel<-glm(y~.,family=binomial(),data=mydata) ...#some other stuff } as I execute this function, it gives error like this Error in inherits(x, "data.frame") : object "mydata" not found So I guess glm here tries to find "m...
2017 Oct 16
1
Download data from NASA for multiple locations - RCurl
...;, > "1970-01-01T03:00:00\t264.595") > ### > > Thus I need to drop the first 13 rows and do the following to add identifying information: Are you having difficulty reading in the data from disk? The `read.table` function has a "skip" parameter. > > ### > mydata <- data.frame(year = substr(x,1,4), That would not appear to do anything useful with x. The `x` object is not a long string. The items you want are in separate elements of x. substr(x,1,4) # now returns [1] "Meta" "" "prod" "para" "para&quot...
2017 Oct 15
1
Download data from NASA for multiple locations - RCurl
...ot;, "Request_time=2017-10-15 22:20:03 GMT", "", "Date&Time Data", "1970-01-01T00:00:00\t267.769", "1970-01-01T03:00:00\t264.595") ### Thus I need to drop the first 13 rows and do the following to add identifying information: ### mydata <- data.frame(year = substr(x,1,4), month = substr(x, 6,7), day = substr(x, 9, 10), hour = substr(x, 12, 13), temp = substr(x, 21, 27)) mydata$city <- rep(cities[1,1], nrow(mydata)) mydata$state <- rep(cit...
2011 Sep 03
5
Problem with by statement for spaghetti plots
...", header=T) fit <- by(tolerance, tolerance$id,function(x) fitted.values(lm(tolerance ~ time, data=x))) fit1 <- unlist(fit) names(fit1) <- NULL interaction.plot(tolerance$age, tolerance$id, fit1,xlab="time", ylab="tolerance", legend=F)/ Here is my code: /mydata <- read.table("https://www.sugarsync.com/pf/D000507_6529035_6683114", header=TRUE) fit <- by(mydata, mydata$id, function(x) fitted.values(lm(outcome ~ age, data=x))) fit1 <- unlist(fit) names(fit1) <- NULL interaction.plot(mydata$age, mydata$id, fit1,legend=F)&...
2010 Jul 16
3
Question about KLdiv and large datasets
Hi all, when running KL on a small data set, everything is fine: require("flexmix") n <- 20 a <- rnorm(n) b <- rnorm(n) mydata <- cbind(a,b) KLdiv(mydata) however, when this dataset increases require("flexmix") n <- 10000000 a <- rnorm(n) b <- rnorm(n) mydata <- cbind(a,b) KLdiv(mydata) KL seems to be not defined. Can somebody explain what is going on? Thanks, Ralf
2017 Oct 15
1
Download data from NASA for multiple locations - RCurl
...; https://hydro1.gesdisc.eosdis.nasa.gov/daac-bin/access/timeseries.cgi?variable=GLDAS2:GLDAS_NOAH025_3H_v2.0:Tair_f_inst&startDate=1970-01-01T00&endDate=1979-12-31T00&location=GEOM:POINT(-71.06,%2042.36)&type=asc2 > ")) > x <- x[-(1:13)] > > mydata <- data.frame(year = substr(x,1,4), > month = substr(x, 6,7), > day = substr(x, 9, 10), > hour = substr(x, 12, 13), > temp = substr(x, 21, 27)) > > mydata$city <- rep(cities[1,1], nrow(mydata))...
2017 Nov 08
1
Help Converting Calendars
How about > p_dates <- paste0(p.dates[[3]], "-", p.dates[[2]], "-", p.dates[[1]]) > myData$p_dates <- p_dates > print(myData, right=FALSE) dates p_dates 1 2017-10-01 1396-7-9 2 2017-10-02 1396-7-10 3 2017-10-03 1396-7-11 > str(myData) 'data.frame': 3 obs. of 2 variables: $ dates : Date, format: "2017-10-01" "2017-10-02" ... $ p_dates:...