similar to: Data.frames can not hold objects...What can be done in the following scenario?

Displaying 20 results from an estimated 1000 matches similar to: "Data.frames can not hold objects...What can be done in the following scenario?"

2012 Jun 09
1
Applying a function to a column of a data frame
Apologees the novice question. Currently climbing up the learning curve of R. Suppose I have the following function and the data.frame: testfun<-function(x=1,y=2) x+y testframe=data.frame(col1=c(1,2),col2=c(3,4)) When evaluating testfun, I want to use the default value for y (which is 2) and for x, I want to feed (one by one) the values in col2 of testframe. How can I achieve this please?
2009 Aug 07
3
How do I plot a line followed by two forecast points?
Good day all, I'm trying to plot a continuous line plot, which is followed by two forecast points eg. one forecast point is 12 months out, and another 24 months out from the last date of the line plot. In my attempts so far, the second plot (the forecast points) is scaled against a new axis scale, thus the two plots are not directly comparable (I need the forecast points to be scaled
2012 Feb 07
6
Setting up infile for R CMD BATCH
Suppose I create an R program called myTest.R with only one line like the following: type <- as.integer(readline("input type (1: type1; 2: type2)? ")) Then I'd like to run myTest.R in batch mode by constructing an input file called answers.R with the following: source("myTest.R") 1 When I ran the following at the terminal: R CMD BATCH answer.R output.Rout it failed
2012 Jul 02
2
Constructing a list using a function...
Hi All I have a dataframe: myframe<-data.frame(ID=c("first","second"),x=c(1,2),y=c(3,4)) And I have a function myfun: myfun<-function(x,y) x+y I would like to write a function myfun2 that takes myframe and myfun as parameters and returns a list as below: mylist $first [1] 4 $second [2] 6 Could you please help me with this? Doesn't seem like the
2012 Jun 16
2
A basic design question for R
Hello R Community, I have the following design question. I have a data set that looks like this (shortened for the sake of example). Gender Age M 70 F 65 M 70 Each row represents a person with an age/gender combination. We could put this data into a data frame. Now, I would like to do some actuarial analysis on this data set. To do so, I need to create and store
2013 Feb 26
1
Could R help with locating coordinates in a serial manner?
Dear R community, My question is not a quick fix one but it would be helpful if you have any advice for me. I have a large data set of many locations in the US and all of these locations are expressed in coordinates (longitudes and latitudes). I need a tool which returns the state that each location is situated in. So the program should return me a vector of state names (eg. NY,CA,OH, etc).
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.
2005 Mar 29
2
strange error with rw2010dev
With rw2010dev I get a strange protect(): protection stack overflow error with a small data frame which otherwise is usable: If anybody wants to have a look I can provide an RData file with the problematic data frame. Doesn't seem to be necessary, the following simulated example generates the error: > testmat <- matrix(1:80, 20,4) > dim(testmat) [1] 20 4 > str(testmat) int
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]]
2006 Dec 20
4
R windows crash (PR#9426)
Full_Name: Robert Denham Version: R-2.4.1 OS: Windows Xp Submission from: (NULL) (61.88.57.1) R gui exits without warning when I run a function which has an argument with a default that is not found. This was a result of an error in a function I wrote, but I thought that it should exit more gracefully than it does. Here is an example: testfun <- function(aa=aa) { aa <-
2009 Jun 20
2
Special characters in Rd example section will cause errors
Hi (Duncan?), The other day I noticed some characters will cause errors in R CMD CHECK because of parse_Rd(), and AFAIK, these chars include '%', '{' and '}'. For example, note the comments in the example section: %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% \name{testfun} \Rdversion{1.1} \alias{testfun} \title{ A Test } \description{ A test } \usage{ testfun() } \value{ NULL }
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
2012 Oct 07
3
get: problem with environments
Dear R users, I am running R-2.15.1 in Linux Slackware64-14.0. Here is my minimal working example: testfun <- function (x) { a <- 0; sapply(X="a", FUN=get, envir=sys.frame(which=x)); } Inside R, that is R called from within a Linux terminal, the following code works: testfun(x=5) print(testfun(x=6)) But within rkward the above code fails and the following works: testfun(x=1)
2011 Jul 12
2
foreach not recognizing functions in memory
All, I am not understanding the scoping used in foreach when it is used inside a function. I keep getting "could not find function" errors for functions that are in memory when I try to use foreach within a function call. I have a simple example below. "testFun" is in memory and works when called by foreach directly, but when I place foreach in a function called
2015 Feb 18
2
Different serialization of functions in interactive vs. batch mode
Hi, I posted this question to the regular help list, but it seems to be this is probably a question that is better addressed on r-devel. Sorry for the double posting. I am using hash-values to cache certain results in R. This caching also depends on the hash-value of the function that is being cached (calculated using the digest package). I noticed that computations that should already be cached
2011 May 23
1
Applying boxplot.stats to multiple value lists
Hello all R gurus, I have a following problem which I hope someone will help me to solve. I have a data.frame in form similar to below. > testframe<-data.frame("Name"=c("aa","aa","aa","aa","aa","bb","bb","bb","bb","bb"),"Value"=c(1,100,1,1,1,100,100,100,100,1))
2012 Aug 08
1
random number generator with SNOW/ Parallel/ foreach
Dear All, I have three classes of questions about generating random numbers with different packages (windows xp 32bit R). . 1. Suppose I would like to use package *foreach*, can I use current Sys.time as a seed? Although I can get the time up to1e-6 second precesion, the code below dose not work well on a local machine with two cores. ################# library(foreach) library(snow)
2001 Oct 05
1
nls() fit to a lorentzian - can I specify partials?
First, thanks to all who helped me with my question about rescaling axes on the fly. Using unlist() and range() to set the axis ranges in advance worked well. I've since plotted about 300 datasets with relative ease. Now I'm trying to fit a lossy oscillator resonance to (the square root of) a lorentzian (testframe$y is oscillator amplitude, testframe$x is drive frequency): lorentz
2015 Feb 18
4
Different serialization of functions in interactive vs. batch mode
Hi Luke, Ah - I see - thank you! This at least points me to a way on how to "fix" this. I tried setting the srcref attribute to NULL, but the hash value is still different and so is the serialization. So this looks like it is one difference, but not all of them Even if all differences were identified - it still leaves me with different behavior between interactive and batch-mode,
2012 Oct 30
1
Is there an lm() equivalent of panel.lmline()?
panel.lmline returns intercept and slope of y ~ x subsetted to the combination of conditioning factors given to xyplot in lattice. for instance: xyplot(Xvalues ~ log(Qvalues)|Tfac, data = df7, panel = panel.lmline) I am looking to find the equivalent formulation for lm() proper. If I do this: lmcal <- lm(Xvalues ~ log(Qvalues):Tfac, data = df7) Only one value of the intercept is returned.