Displaying 20 results from an estimated 30000 matches similar to: "Dynamic resizing of lists, dataframes (newbie question)"
2011 Jun 30
1
Match strings across two differently sized dataframes and copy corresponding row to dataframe
Hello-
Sorry, this is a bit of a noob question, but I can't seem to progress
it any further.
I have two dataframes which contain a series of strings which exactly
match. The problem is one has more rows than the other (more cases
have been added) and they have been sorted so that they are not in the
same order. The smaller dataframe, though, contains in another column
which has codes
2011 Oct 05
2
aggregate function with a dataframe for both "x" and "by"
I have 2 dataframes. "mydata" contains numerical data. "mybys" contains
information on the "group" each row of the data is in. I wish to aggregate
each column in mydata using the corresponding column in mybys.
Please see the example below. What is a more elegant or "better" way to
accomplish this task?
Thanks!
mydata =
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[,'v1'] it is?
Thanks
Frans
-------------------
Frans Marcelissen
2009 Sep 03
2
dividing a dataframe column by different constants
Dear R users, today I've got the following problem.
Here you are a dataframe as example.
There are some SAMPLES for which a CONCentration was recorded through TIME.
The time during which the concentration was recorded is not always the same,
10 points for Sample A, 7 points for Sample B and 11 for sample C
Also the initial concentration was not the same for the three samples.
I would like
2011 Jun 20
2
Replace selected columns of a dataframe with NA
I am using the following command to replace all the missing values and
assorted typos in a dataframe with NA:
mydata[mydata>80]=NA
The problem is that the first column contains values which should be
more than 80, so really I want to do it just for
mydata[,2:length(mydata)]
I can't seem to re-write the code to fit:
mydata[,2:length(mydata)>80]=NA # no error message, but doesn't
2006 Apr 29
1
splitting and saving a large dataframe
Hi,
I searched for this in the mailing list, but found no results.
I have a large dataframe ( dim(mydata)= 1297059 16, object.size(mydata=
145280576) ) , and I want to perform some calculations which can be done by
a factor's levels, say, mydata$myfactor. So what I want is to split this
dataframe into nlevels(mydata$myfactor) = 80 levels. But I must do this
efficiently, that is, I
2007 Feb 13
1
Missing variable in new dataframe for prediction
Hi,
I'm using a loop to evaluate several models by taking adjacent variables from my dataframe.
When i try to get predictions for new values, i get an error message about a missing variable in my new dataframe.
Below is an example adapted from ?gam in mgcv package
library(mgcv)
set.seed(0)
n<-400
sig<-2
x0 <- runif(n, 0, 1)
x1 <- runif(n, 0, 1)
x2 <- runif(n, 0, 1)
x3 <-
2003 May 18
1
How to split a dataframe into smaller constituent dataframes
I have read a large dataset into a dataframe using RODBC, the rows of data
in the dataframe are (integer) timestamped and I would like to divide the
original dataframe into n smaller dataframes where dataframe 1 contains all
rows that had timestamps falling in the period 0-x1 minutes, dataframe 2
contains all rows that had timestamps falling between x1+1 and x2, etc..
Does anyone know how to
2008 Jan 08
1
retaining "POSIXct" formatting when using apply(muff, FUN=MAX) on POSIXct dataframe?
How do I retain "POSIXct" formatting when using apply, with FUN=max?
#example:
mydata <- rep(Sys.time(), 10)
mydf <- data.frame(matrix(data=mydata, nrow=2, ncol=length(mydata) ) )
for(i in seq(mydf))class(mydf[[i]]) <- class(mydata)
str(mydf)
maxdates <- apply(mydf,2,max,na.rm=T)
str(maxdates)
#Why is the formattign now "chr", and not
2005 Apr 13
1
How to plot Contour with NA in dataframe
Dear friends,
I am trying to produce Contour Plot with R, but there are some NA
in my data matrix. After I ran the following R script, I got the error
message:"no proper `z' matrix specified". Does anybody know how to plot
contour chart with R for the non-strict matrix?
Thank you in advance!!!
2007 Aug 11
1
Replace NAs in dataframe: what am I doing wrong
Dear R-users,
My script imports a dataset from a csv file, in which missing values are
represented by ".". This importation is done into a dataframe using the
read.table function with na.strings = "." Then I want to replace the
NAs in the first column of the dataframe by "Missing data". I am using
the following code to do so :
2010 Apr 03
1
"moving product", by rows, of a dataframe?
What is a "good" way to calculate the "moving product", for each row of a dataframe, where I wish to be able to specify the length of the moving product? Depending on my needs, I'd like to be able to specify the "length" over which to calculate the moving average (in this example, length=3).
For example, if I have a dataframe with 20 rows and 6 columns, and I
2007 Mar 15
2
replacing all NA's in a dataframe with zeros...
I've seen how to replace the NA's in a single column with a data frame
*> mydata$ncigs[is.na(mydata$ncigs)]<-0
*But this is just one column... I have thousands of columns (!) that I need
to do this, and I can't figure out a way, outside of the dreaded loop, do
replace all NA's in an entire data frame (all vars) without naming each var
separately. Yikes.
I'm racking my
2012 Sep 17
6
help with calculation from dataframe with multiple entries per sample
Hi
I have a dataframe similar to:
>Sample<-c(1,1,1,2,2,2,3,3,3)
>Time<-c(1,2,3,1,2,3,1,2,3)
>Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5)
>mydata<-as.data.frame(cbind(Sample,Time,Mass))
Sample Time Mass
1 1 1 3.0
2 1 2 3.1
3 1 3 3.4
4 2 1 4.0
5 2 2 4.3
6 2 3 4.4
7 3 1 3.0
8 3 2 3.2
9 3 3
2007 Nov 24
2
'Split' character
Dear R-users,
The following code splits a very simple dataframe into a list, each element of
the list being one line of the dataframe. You will see that the split function
names each element of the list by using uses the content of a and b and merging
them with a "." character. Is there a way to customize this character?
a<-1:10
b<-21:30
mydata<-data.frame(a,b)
2003 Nov 04
1
AW: R function help arranged in categorical order ?
There is a very nice Search Engine, with Keywords arranged by topic, that
comes with R.
If you are under Windows (and have Html help installed), you can find this
in the Help menu, under "Html help".
(The relevant file can also be found as
...\doc\html\search\SearchEngine.html.)
Maybe this helps,
Heinrich.
> -----Urspr?ngliche Nachricht-----
> Von: Neil Osborne
2009 Sep 05
1
Convert dataframe to array of records
I would like to convert a dataframe to an array of lists, one for every
record. A natural choide is apply as.list to the rows. However, as it seems,
as.list() automatically converts all list elements to the same datatype. Eg:
myData <- data.frame(a="foo",b=as.logical(rbinom(10,1,.5)));
apply(myData,1,as.list);
In this output, all boolean values have been converted to character
2012 Aug 01
2
sub setting a data frame with binomial responses
Hi everyone,
Let me have a dataframe named ?mydata? and created as below,
*> n=c(5,5,5,5) #number of trils
> x1=c(2,3,1,3) ) #number of successes
> x2=c(5,5,5,5) #number of successes
> x3=c(0,0,0,0) #number of successes
> x4=c(5,0,5,0) #number of successes
> mydata=data.frame(n,x1,x2,x3,x4)
> mydata*
n x1 x2 x3 x4
1 5 2 5 0 5
2 5 3 5 0 0
3 5 1 5 0 5
4 5 3 5 0
2008 Jan 03
2
retaining formatting when converting a vector to a matrix/data.frame?
Please see example code below.
I have a vector ("mydata") of length 10. "mydata" can have various formats (e.g. numeric, text, POSIXct, etc) I use the matrix and data.frame functions to convert "mydata" to a dataframe ("mydf") of 2 columns and 5 rows.
What is a "good" way to ensure that the format is retained when I create the
2010 Mar 05
1
How to parse the arguments from a function call and evaluate them in a dataframe?
Hi,
I would like to write a function which has the following syntax:
myfn <- function(formula, ftime, fstatus, data) {
# step 1: obtain terms in `formula' from dataframe `data'
# step 2: obtain ftime from `data'
# step 3: obtain fstatus from `data'
# step 4: do model estimation
# step 5: return results
}
The user would call this function as:
myfn(formula=myform,