Displaying 20 results from an estimated 13000 matches similar to: "inserting columns in the middle of a dataframe"
2012 Nov 09
3
if between 500-600 give 550
I have a data frame somewhat like this:
myframe <- data.frame (ID=c(2,3,4,5), Hunger =c(415,452,550,318 ))
myframe
Now I would like to add a column to the right which summarizes the values
for Hunger somewhat to reduce the number of values: If the values for Hunger
are between
300-400 I would like to insert the number 350,
between
400-500 insert 450
between
500-600 insert 550
Does
2011 Aug 01
1
Inserting column in between -- "better" way?
Folks:
I consider my reply below rather clumsy: One has to keep track of
index numbers other than that which is inserted and must separately
change column names. Is there as "essentially better" way to do this,
either via base R or via an R package. I leave it to you to define
"essentially better."
Thanks.
Cheers,
Bert
On Mon, Aug 1, 2011 at 10:17 AM, Bert Gunter
2004 May 11
2
lm with predictor matrix
Hello,
can someone give me an example of how to fit a linear model where the
response is a matrix, please? (other than a loop over lm calls)
The ?lm points me to model.matrix but it is not clear to me how to use a
model matrix in an lm call.
fit<-lm(headmatrix ~ tailmatrix) causes problems as soon as I
use predict(fit,newframe). The variables in tailmatrix are not found in
2005 Sep 08
1
Converting a matrix to a dataframe: how to prevent conversion to factor
Colleages
I am running R 2.1.0 on a Mac (same problem occurs in Linux). In
some situations, I have mixed text/numeric data that is stored as
characters in a matrix. If I convert this matrix to a dataframe, the
numeric data becomes factors, not what I intend.
TEXT <- paste("Text", 1:4, sep="")
NUMBERS <- 10 + 4:1
MATRIX <- cbind(TEXT,
2007 Jul 17
2
SLLOOOWWW function ...
Does anybody have any insight into how to make this faster?
I suspect, that the rounding going on may be an issue, as is the stepping
through data frame rows using integers ...
If you have the patience to teach a noob, he will highly appreciate it ;0)
Joh
digit <- 4
for (minute in seq(from=25,to=lrange[2])){
# Extract all data associtaed with the current time (minute)
frame <-
2018 Apr 15
4
Adding a new conditional column to a list of dataframes
Hi all ..,
I have a list of 7000 dataframes with similar column headers and I wanted to add a new column to each dataframe based on a certain condition which is the same for all dataframes.
When I extract one dataframe and apply my code it works very well as follows :-
First suppose this is my first dataframe in the list
> OneDF <- Mylist[[1]]
> OneDF
ID Pdate
2010 Nov 09
4
help to add a new column filled with value 1
Dear All,
I have a data frame with 5 column and 201 row data. I want to add one
more column between column 1 and 2 with value of 1. So the new column
has to be the second column filled with 1. Any help will be
appreciated.
Thanks for your time.
Thanks & Rg
Mohan L
2010 Nov 10
1
Inserting Missing Data
Greetings
I'm attempting to insert missing data on the smallest size class of
cave cricket instars into a data frame. The data involve censusing
photoplots (plots) of roosting cave crickets in which we discern in four
instars or size classes. I need to insert data on size class one into a
data frame that already has data on size classes two through four. The
data can be merged by their
2011 Sep 13
1
implicit data frame reference
If I create an aggregation like this:
aggregate(lastYear[,8:10],list(Stadium=lastYear$STAD),mean)
I'll get a new data frame, which I can order if I assign it like this:
newFrame <- aggregate(lastYear[,8:10],list(Stadium=lastYear$STAD),mean)
newFrame[order(newFrame$TEMP),]
But.. if I just want to do this in one statement, what can I do? If this
was perl, I'd be using something like
2005 Aug 12
1
as.formula and lme ( Fixed effects: Error in as.vector(x, "list") : cannot coerce to vector)
This is a continuing issue with the one on the list a long time ago (I
couldn't find a solution to it from the web):
--------------------------------------------------------------------------
> Using a formula converted with as.formula with lme leads
> to an error message. Same works ok with lm, and with
> lme and a fixed formula.
>
> # demonstrates problems with lme and
2001 Feb 23
1
as.formula and lme ( Fixed effects: Error in as.vector(x, "list") : cannot coerce to vector)
Using a formula converted with as.formula with lme leads
to an error message. Same works ok with lm, and with
lme and a fixed formula.
# demonstrates problems with lme and as.formula
demo<-data.frame(x=1:20,y=(1:20)+rnorm(20),subj=as.factor(rep(1:2,10)))
demo.lm1<-lme(y~x,data=demo,random=~1|subj)
print(summary(demo.lm1))
newframe<-data.frame(x=1:5,subj=rep(1,5))
2012 Nov 27
5
loop with date
Hello,
I tried to construct my very first loop today and completly failed :-(
Maybe someone can help me?
I have a dataframe somewhat like this one:
myframe <- data.frame (Timestamp=c("24.09.2012 09:00", "24.09.2012 10:00",
"24.09.2012 11:00",
"25.09.2012 09:00", "25.09.2012 10:00",
"25.09.2012
2018 Apr 15
0
Adding a new conditional column to a list of dataframes
> On Apr 15, 2018, at 4:08 AM, Allaisone 1 <Allaisone1 at hotmail.com> wrote:
>
>
> Hi all ..,
>
>
> I have a list of 7000 dataframes with similar column headers and I wanted to add a new column to each dataframe based on a certain condition which is the same for all dataframes.
>
>
> When I extract one dataframe and apply my code it works very well as
2006 Aug 28
2
regex scares me
Hi, apologies if this is too simple but I've been stuck on the following for
a while:
I have a vector of strings: filenames with a name before the extension and a
variety of possible extensions
I want to select only those files with:
1) a ".tab" extension
AND
2) the character sequence "lad" anywhere in the name of the file before the
extension.
Surely this
2010 May 17
1
suggestions/improvements for recoding strategy
I am recoding some data. Many values that should be 1.5 are recorded
as 1-2. Some example data and my solution is below. I am curious about
better approaches or any other suggestions. Thanks!
# example input data
myData <- read.table(textConnection("id, v1, v2, v3
a,1,2,3
b,1-2,,3-4
c,,3,4"),header=TRUE,sep=",")
closeAllConnections()
# the first column is IDs so remove
2006 Nov 06
7
Colour-coded Editor for R Code
Do any of you know any simple programming editors for R scripts which offer
basic colour-coding and bracket-matching facilities?
Dregging through scripts to find a missing comma or parentheses is something
I'd rather do less of...
Jon Minton
[[alternative HTML version deleted]]
2007 Apr 23
1
automating merging operations from multiple dataframes
Hi,
I have a set of dataframes names AINDSLIM, BINDSLIM, CINDSLIM ... NINDSLIM
In each dataframe I want to extract two variables, “pid” and “{w}region”,
where {w} means “a”, “b”, “c”, ...”n”
At the moment my code looks like:
> PidRegion <- data.frame(pid=XWAVEID$pid)
> this.region <- AINDSLIM[,c("pid", "aregion")]
> PidRegion <- merge(PidRegion,
2009 May 26
1
Bug in "$<-.data.frame" yields corrupt data frame (PR#13724)
Full_Name: Steven McKinney
Version: 2.9.0
OS: Mac OS X 10.5.6
Submission from: (NULL) (142.103.207.10)
A corrupt data frame can be constructed as follows:
foo <- matrix(1:12, nrow = 3)
bar <- data.frame(foo)
bar$NewCol <- foo[foo[, 1] == 4, 4]
bar
lapply(bar, length)
> foo <- matrix(1:12, nrow = 3)
> bar <- data.frame(foo)
> bar$NewCol <- foo[foo[, 1] == 4, 4]
2002 Feb 09
1
How to access objects outside an R function
Dear R-Users,
I have a dataframe (''forexdata'') of daily returns from the foreign exchange market for three currencies - British Pound (bp), Canadian Dollar(cd),
Deustche Mark (dm) vis-a-vis the US Dollar and the Date Of
Trade(yymmdd).
For some dates the returns are missing (recorded as zero) as there
were no trades in that currency for that date. My task is to
substitute the
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