Displaying 20 results from an estimated 30000 matches similar to: "Sorting a dataframe by one column?"
2006 Feb 24
3
Sorting alphanumerically
I'm trying to sort a DATAFRAME by a column "ID" that contains
alphanumeric data. Specifically,"ID" contains integers all preceeded
by the character "g" as in:
g1, g6, g3, g19, g100, g2, g39
I am using the following code:
DATAFRAME=DATAFRAME[order(DATAFRAME1$ID),]
and was hoping it would sort the dataframe by ID in the following manner
g1, g2, g3, g6, g19,
2004 Jun 06
4
Request help writing a function
I have been wrestling with this function for quite a while, and am not making headway.
1) I want to apply a function to the following columns of a dataframe:
myfunction. <- apply(ph5028[,c(83:107)],2,function(x) ...
2) Within each of the above columns there is a single numeric code, 1, 2 or 3 or an NA.
3) My goal is to determine the percent of time each person used a 2 code. So if a person
2006 Feb 28
2
vector math: calculating a rolling 12 row product?
I have a dataframe of numeric values with 30 ?rows?
and 7 ?columns?.
For each column, beginning at ?row? 12 and down to
?row? 30, I wish to calculate the ?rolling 12 row
product?. I.e., within each column, I wish to
multiply all the values in row 1:12, 2:13,
19:30.
I wish to save the results as a new dataframe, which
will have 19 rows and 7 columns.
2006 Feb 08
6
dataframe subset
I have a dataframe with a column, say "x" consisting of values, each
value appearing different times, e.g.
x: 1,1,1,1,2,2,4,4,4,9,10,10,10,10,10 ...
and a vector, including e.g.:
y: 2,9,10,...
I need a subset of the dataframe: all rows where x is equal to one of
the values in y. Currently I use a loop for this, but because x and y
are large this is very slow.
Is there any idea how to
2004 Sep 15
5
replacing NA's with 0 in a dataframe for specified columns
I know that there must be a cool way of doing this, but I can't think
of it. Let's say I have an dataframe with NA's.
> x <- data.frame(a = c(0,1,2,NA), b = c(0,NA,1,2), c = c(NA, 0, 1, 2))
> x
a b c
1 0 0 NA
2 1 NA 0
3 2 1 1
4 NA 2 2
>
I know it is easy to replace all the NA's with zeroes.
> x[is.na(x)] <- 0
> x
a b c
1 0 0 0
2 1 0 0
3 2 1
2006 Feb 24
3
Summarize by two-column factor, retaining original factors
I am having trouble doing the following. I have a data.frame like
this, where x and y are a variable that I want to do calculations on:
Name Year x y
ab 2001 15 3
ab 2001 10 2
ab 2002 12 8
ab 2003 7 10
dv 2002 10 15
dv 2002 3 2
dv 2003 1 15
Before I do all the other things I need to do with this data, I need
to summarize or collapse the data by name and year. I've
2006 Feb 03
1
How to get all the data in a specific column from a dataframe?
Dear R-helpers:
Suppose I have a datafram called "test_frame" like this
col1 col2 col3 col4
r1 x x x x
r2 x x x x
r3 x x x x
.. x x x x
rn x x x x
I know I can get data of col3 by using test_frame[,3].
My question is, if I want to do this by specifying "col3" rather
2005 Feb 08
1
Plotting estimated betas, standard error
Hello,
I was wondering, is there a way to plot estimated betas and standard
deviations that I've generated?
Specifically, I have the following:
A matrix of estimated betas (two different betas, 4 different simulations -
categories).
A matrix of estimated standard errors corresponding to each of those betas.
I would like to plot the estimated beta, and make a confidence
2004 Mar 19
3
how to fix a factor
Hi all,
I created a data frame with three factors, plus the response that
looks like this:
x1 x2 x3 y
a 1 1 0.3
a 2 1 0.1
b 1 1 0.4
c 4 3 0.1
...
I would like to analise the effect of two of them, keeping the third fixed
(I already know the effect of the last). The reason why I don't create several
data frames for each value of the thirs factor is simply convenience (I'd like
to be able
2004 Jun 09
3
Dot chart question
Running R 1.8.1 on a Windows machine
In dotchart, I would like to shrink the labels on the tick marks (that
is, the numbers) without shrinking anything else. I could not find this
in either the Rhelp archives or in ?dotchart, which recmmends cex to
avoid 'label overlap', but cex shrinks all the characters in the plot.
Is there a way to do this?
Thanks
Peter
Peter L. Flom, PhD
2009 Jul 30
4
edit.row.names taking row names from the edited dataframe
Hi all,
I am struggling to work out how to use the rownames from an edited dataframe
rather than the row names from the original dataframe. In my data set i'm
trying to extract several rows of data on particular individuals, i don't
doubt i'm using the long way round but what i have in the way of a script is
this:
##selecting the IDs from the dataframe individually
2004 May 28
1
dotchart questions
I am trying to put 3 dotcharts side-by-side with minimal space between
each. Each chart is for a different variable, but the vertical axes are
the same.
I want to have vertical axis labels on the lefthand chart but no
vertical axis labels on the other two. Plus, I would like very little
space between charts 1 & 2 and between charts 2 & 3.
I have one approach but am not too happy with
2006 Jan 11
3
SPSS and R ? do they like each other?
... and is there also such a nice tool (like spss.get) for exporting
data frames to SPSS? write.table does not keep the data frame labels -
neither did the other exporting tools that I found.
Thanks!
Michael
[[alternative HTML version deleted]]
2005 May 19
2
laten class analysis
Dear List,
just a little question,
I am interested in Latent Class Analysis and
I guess if there is a package for this pourpose
thank for you help,
Simone
2009 May 12
2
SAS PROC SORT nodupkey
Hi,
I have the following data and I would like to delete douple names, it is almost similar to SAS PROC SORT nodupkey! Is there any function in R does this?
x1 <- rnorm(11,5,1)
x2 <- runif(11,0,1)
nam <-paste("A", c(1:4,4,5:9,9), sep=".")
mydata <- data.frame(x1,x2)
crownames(mydata) <- nam
Many thanks in advance,
Amor
[[alternative HTML version
2005 Nov 10
2
polynomials transformation
Dear All,
Need some help in polynomials transformation to get the coefficients. I have tried "poly.transform" as applied in S-plus but it does not work.
Thanks in advanced for any helps.
Regards.
Abd. Rahman Kassim (PhD)
Head Forest Ecology Branch
Forest Management & Ecology Program
Forestry and Conservation Division
Forest Research Institute Malaysia
Kepong 52109
Selangor,
2005 Jul 08
1
how to do something like symptoms==c('a', 'e', 'z')
RenE J.V. Bertin wrote:
> I find myself doing lots of tests like
>
>
>>subset( data, symptoms=='a' | symptoms=='e' | symptoms=='z' .... )
>
>
> with symptoms one of the factors contained in the data frame.
>
> and I wonder if there is not an existing operator or function which implements this sort of repeated conditional in a more
2005 Jan 26
2
reshape (a better way)
Hi,
I am using the NLSY79 data (longitudinal data from the Bureau of labour
stats in the US). The extractor exctracts this data in a "wide" format and
I need to reshape it into a long format.
What I am doing right now is to do it in chuncks for each and evry
variable that is varying and then I merge the data together. This is
taking a long time. my question is:
How do I specify that
2009 Apr 16
2
Translate the elements of a dataframe
The second beginner question. I want to create a new dataframe, where
each element of the original dataframe is translated to 1 if it was "+",
to 0 if it was "-" to -1 otherwise. I could do with:
Lines <- "a b c d
+ - + +
+ + + -
+ 1 - '+ '
- + + +
+ N - +"
DF <-
2006 Mar 09
3
substituting values
dear list,
i have a matrix with missing values like
1 2 3 4 x
x 2 2 2 2
2 2 2 x 2
the x stands for the missing value.
i have to substitute it to NA
substitute or replace didn´t work out, as they are for vectors only
however matrix[,i] also didn´t work.
can anybody tell me, who i can change these values easily?
thanks stefan
[[alternative HTML