Displaying 20 results from an estimated 50000 matches similar to: "Creating data frame from existing data frame"
2009 Sep 13
1
Manage an unknown and variable number of data frames
Hi,
In the code below I create a small data.frame (dat) and then cut it
into different groups using CutList. The lists in CutList allow to me
choose whatever columns I want from dat and allow me to cut it into
any number of groups by changing the lists. It seems to work OK but
when I'm done I have a variable number of data frames what I need to
do further operations on and I don't know
2009 Mar 19
2
Randomly splitting a data frame in half
I have a data frame in long format and I would like to randomly divide
this data frame in half. The data frame consists of 39622 rows and I
initially tried ...
randomsample1 <- data[sample(nrow(data),19811), ]
Where allows me to randomly select half of the rows and assign them to
randomsample1 but then I couldn't figure out how to select those rows
that were not selected and assign
2006 May 18
2
extracting values from data.frame given arbitrary keys
Hi all.
I have a pure R programming question.
Having a data.frame with a 'data' variable and some (>1) ID variables
(either numeric or factors), I would extract a sequence of data values given
a sequence of ID values.
Here's an example. Build a dataset:
n1 <- 5
n2 <- 2
v1 <- rep(factor(1:n1),2)
v2 <- rep(1:n2,5)
x <- rnorm(10)
dat <- data.frame(x=x, v1=v1, v2=v2)
2006 Sep 06
1
Covariance/Correlation matrix for repeated measures data frame
All,
I have a repeated measures data frame and was wondering if the
covariance matrix can be
calculated via some created indexing or built-in R function.
Specifically, say there are 3 variables, where potassium concentration
is measured 6 times on each patient.
Patient number (discrete)
Time (1 to 6, discrete)
Potassium (continuous variable)
I want the covariance/correlation matrix for the
2004 Dec 05
1
matrix of 1,0's to a data.frame of factors
Hi, I have an integer matrix consisting of 1's and 0's and I would like
to convert this to a data.frame where each column of the matrix becomes
a factor variable.
Now, some columns of the matrix have only 1's or only 0's as a result
there is only 1 level for those columns in the data.frame. However it is
required that each factor have 2 levels. So my solution is:
m <-
2009 Jul 24
2
How to find the min and max of two variables in a data frame
I have two variables in a data frame, I want to generate two additional
variables. For every observations (i.e. every row), I want the first new
variable 'min' to carry the minimum of the two existing variables, and I
want the second new variable 'max' to carry the maximum of the two existing
variables. I then want to sort the data frame by min and max, and delete
duplicated rows
2010 May 11
2
Can not restore domain from a shared state file
Hi,
I have two KVM host: h1 and h2, both of them mount an NFS directory as a
shared storage.
I can save (virsh save <domain> <file>) a domain in h1 to a state file in
the shared storage successfully, but failed to restore it from h2 with the
following error message:
# virsh restore testRes.dat
error: Failed to restore domain from testRes.dat
error: operation failed: failed to start VM
2005 Feb 28
5
persistance of factor levels in a data frame
Hi,
Just something I don't understand:
data <- data.frame(V1=c(1:12),F1=c(rep("a",4),rep("b",4),rep("c",4)))
data_ac <- data[which(data$F1 !="b"), ]
levels(data_ac$F1)
Why the level "b" is always present ?
thanks
Tristan, R 2.0.1 for Linux Fedora 3
--
------------------------------------------------------------
Tristan
2004 Dec 01
2
Data Frame Manipulations
Hi
I have used merge() to merge two data frames, very much like performing
a SQL join. Now I want to do a few different SQL-style things and I
wondered if there were functions to do it...
Is there a "group by" style function? For example if I merge() two data
frames and end up with multiple rows for each "id", and want to take the
average of the values of a particular
2008 Mar 27
2
colMeans in a data.frame with numeric and character data
Hi all,
I would like to know if it is posible by, someway, to get colMeans from
a data.frame with numeric as well as character data, dispersed all over
the object. Note that I would like to get colMeans neglecting character
data.
I am really in need of some function proceeding in that way…
All the best
Diogo André Alagador
[[alternative HTML version deleted]]
2005 Mar 21
1
Remove columns from data-frame
Hello,
I'm new to the list, hello everybody! :-)
I have a question. I looked carefully through the documentation and
googled, and found no answer, so I'm posting it here.
Let's say I have a data frame with lots of columns (about 300), which
are factors. Many columns-factors have only one level, for example all
are "Yes" or all are "No".
If I try to do a
2009 Feb 02
2
concatenating 2 text columns in a data.frame
Hi,
I'm trying to concatenate values from two columns in a data frame. For
example, I have the following data.frame:
C1 C2 C3 C4 C5
A B *F C* Q
G H *I J* T
K D *R S* E
P L *M N* O
I'd like to concatenate text from columns C3 and C4, to yield either a
list or vector, like so:
NewCol
FC
IJ
RS
MN
Is this feasible in R?
Thanks!
2005 Mar 11
3
aov or t-test applied on all variables of a data.frame
Hi
I have a data.frame with say 10 continuous variables and one grouping
factor (say 3 levels)
how can I easily (without loops) apply for each continous variable e.g.
an aov, with the grouping factor as my factor (or if the grouping factor
has 2 levels, eg. a t-test)
thanks for a hint
cheers
christoph
2006 Nov 28
2
Sorting a data frame when you don't know the columns
Hi
Sorry to ask such a well oiled question, but even with multiple google hits I don't think this has been answered very well.
It's all well and good doing a sort of a data frame on multiple columns when you know in advance which columns you want to sort on, but what about when the names of the columns you wish to sort on are in a vector?
At the minute I'm messing about with
2006 Jan 23
3
ordering a data frame to same order as a chr vector
Hi all,
I've got a data frame that has an identical column to a chr vector. I would
like to use the chr vector to order the rows of the data frame to be
identical to the order in the chr vector (the contents of the chr vector are
completely identical to one col of the data frame), but this is proving
trickier than it sounds..
Any help would be much obliged,
-Ken
2006 Jun 20
3
Create variables with common values for each group
Dear all,
sorry, this is for sure really basic, but I searched a lot in the
internet, and just couldn't find a solution.
The problem is to create new variables from a data frame which
contains both individual and group variables, such as mean age for an
household. My data frame:
df
hhid h.age
1 10010020 23
2 10010020 23
3 10010126 42
4 10010126 60
5 10010142
2004 Oct 29
2
lag variable addition to data frame question
Hi,
I was wondering if there is a more efficient way of handling the following method of creating a lagged value in a data frame without using the recursive
'for(i in 1:n)' loop and without using as.ts
#Steps to creating a lag variable in a data frame 'my.dat.fr'
# with 275 columns, 2400 rows of numbers and factors . The #variable x is a factor of #with five different levels
the
2007 Apr 02
1
Res: Create a new var reflecting the order of subjects in existing var
Um texto embutido e sem conjunto de caracteres especificado associado...
Nome: n?o dispon?vel
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070401/68a57089/attachment.pl
2006 Sep 12
1
Transformation of a data frame
Dear R-helpers,
Apologies in advance for this (probably) simple question. I've searched the
R Archive and can't seem to find a solution to my problem.
I have a data frame of vegetation quadrat data with the following format:
Q S C
1 A 5
1 B 10
1 C 50
1 D 10
2 A 20
2 E 10
2 C 40
3 D 5
3 F 1
3 G 5
3 B 75
Where Q is the sample (vegetation quadrats), S is the species and C is the
2007 Apr 03
1
Behavior of seq_along (was: Create a new var reflecting the order of subjects in existing var)
I am moving this from r-help to r-devel. Based on offline communications
with Jim, suppose dat is defined as follows:
set.seed(123)
dat <- data.frame(ID= c(rep(1,2),rep(2,3), rep(3,3), rep(4,4),
rep(5,5)), var1 =rnorm(17, 35,2), var2=runif(17,0,1))
# Then this ave call works as expected:
ave(dat$ID, dat$ID, FUN = function(x) seq_along(x))
# but this apparently identical calculation