Displaying 20 results from an estimated 10000 matches similar to: "Expanding rows of a data frame into multiple rows"
2009 Feb 09
2
Generating new variable based on values of an existing variable
Dear R Help-Listers:
I have a problem that seems like it should have a simple solution, but I've spent hours on it (and searching the r-help archives) to no avail. What I'd like to do is to generate a new variable within a data frame, the values of which are dependent upon the values of an existing variable within that data frame.
Assume that I have the following data:
2010 Mar 05
2
How to assign week numbers to a time-series
Hello everyone,
My progress has stalled on finding a way of creating a somewhat complicated variable to add to my existing dataframe and I am hoping one of you could help me out. The dataframe below contains only a fraction of the data of my complete dataframe, but all of the variables. What I want to do is add another variable named 'WEEK' to this dataframe that is assigned 1 for row 1
2007 Sep 04
3
variable format
Okay, I want to do something similar to SAS proc format.
I usually do this...
a <- NULL
a$divisionOld <- c(1,2,3,4,5)
divisionTable <- matrix(c(1, "New England",
2, "Middle Atlantic",
3, "East North Central",
4, "West North Central",
5,
2008 Oct 13
3
lattice panel question
Dear R users,
How to change lattice panel label/text from the automatically generated
label (based on the conditioning) to our own set of label?
for example:
someStuff <- data.frame(area = rep(c("SOUTH", "NORTH", "EAST", "WEST"), each
= 25),
group = rep(c("A","B","C","D"), each = 5),
2008 Jun 23
3
subset with multiple criteria
This should be theoretically very simple, but I dont get the elegant
answer (without looping).
I've got a long (thousands of rows) data frame:
> E.coor[1:10,]
east north dat
1 582650 4248850 0.8316848
2 582750 4248850 0.7230272
3 582850 4248850 0.3250818
4 582950 4248850 0.6144006
5 583050 4248850 0.8706312
6 583150 4248850 0.2149651
7 583250 4248850 0.1659519
8
2005 Jun 25
1
Confidence interval bars on Lattice barchart with groups
I am trying to add confidence (error) bars to lattice barcharts (and
dotplots, and xyplots). I found this helpful message from Deepayan
Sarkar and based teh code below on it:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/50299.html
However, I can't get it to work with groups, as illustrated. I am sure I
am missing something elementary, but I am unsure what.
Using R 2.1.1 on various
2007 May 21
1
help with this indexing
Hi all,
Let's say I have a long data frame and a short one, both with three
colums: $east, $north, $value
And I need to fill in the short$value, extracting the corresponding
value from long$value, for coinciding $east and $north in both tables.
I know the possibility:
for (i in 1:length(short$value)){
short$value[i] <- long$value[long$east==short$east &
long$north==short$north]
}
How
2005 Dec 08
2
'mean' and 'sd' calculations do not match
Dear list,
I am using R 2.1.1 on a Fedora 3 Linux, 32 bit PC.
If I compute the aggregated mean and the standard deviation I get
standard deviation values for factors where the mean was not computed.
It seems to me that this is somehow related to the NA values. But I
don't quite understand what is going wrong?
Could it be related to the data import already? Some of the imported
data got the
2011 Jul 28
1
Reading name-value data
I have a file of data where each line is a series of name-value pairs, but
where the names are not necessarily the same from line to line, e.g.
a=1,b=2,d=5
b=4,c=3,e=3
a=5,d=1
I would like to create a data frame which lines up the data in the
corresponding columns. In this case, this would be
data.frame( a = (1, NA, 4), b = (2, 4, NA), c = (NA, 3, NA), d = (5, NA,
1), e = (NA, 3,
2010 Apr 14
2
search and replace
I have a dataframe with almost a million rows which has one column
with strings. That column has several entries with the words "South",
"North", "East" and "West" which I would like to replace with S, N, E,
and W, respectively. Obviously, I can use gsub multiple times df
$col2 <- gsub("West", "W", df$col2) which will require
2012 Mar 07
2
Remove a word from a character vector value XXXX
Hi everyone,
What is the easiest way to remove the word Average and strip leading
and trailing blanks from the character vector (d5.Region) below?
.nrow.d5. d5.Region
1 1 Central Average
2 2 Coastal Average
3 3 East Average
4 4 Metro East Average
5 5 Metro North Average
6 6 Metro South Average
7
2017 Sep 07
0
ISO3 code to 7 continents names
> On Sep 7, 2017, at 12:21 PM, Miluji Sb <milujisb at gmail.com> wrote:
>
> df is a data frame consisting of one variable (iso3 codes) such as
>
> USA
> RUS
> ARG
> BGD
> ITA
> FRA
>
>
> Some of these iso3 codes are repeated and I would like the corresponding continent name, the countrycode package does not seem to distinguish between North and
2009 Feb 27
1
cross tabulation: convert frequencies to percentages
Hello,
might be rather easy for R pros, but I've been searching to the dead
end to ...
twsource.area <- table(twsource, area, useNA="ifany")
gives me a nice cross tabulation of frequencies of two factors, but
now I want to convert to pecentages of those absolute values. In
addition I'd like an extra column and an extra row with absolute sums.
I know, Excel or the
2018 Jun 01
4
Regroup and create new dataframe
Hello folks,
I have a big project to work on and the dataset is classified so I am just
going to use my own example so everyone can understand what I am targeting.
Let's take Target as an example: We consider three brands of tape: Target
brand, 3M and Avery. The original data frame has 4 columns: Year of Record,
Product_Name(which contains three brands of tape), Sales, and Region. I
want to
2009 Aug 21
4
Where to put source code?
I'm trying to move from Matlab to R, and I'm stuck even getting
started. This sounds to me like the dumbest question in the world
but... how does one put R source code in files? Over the last three
days I've gone front to back through the Introduction to R and the R
Language Definition, and while I'm excited that the language is so
Lispish, none of what I read described how to
2013 Jul 07
2
The *tmp* variable
When complex assignments are performed, the R interpreter creates, then
removes a special variable *tmp*. However, when byte compiling is enabled,
it seems that a different mechanism for making compound assignments is used.
Would it be possible to eliminate *tmp* from interpreted R code as well? It
might be useful for a function to lock its own environment, and the
appearance and disappearance of
2012 Jul 18
2
plotting points to a map
Dear R users,
I have a city map in shape file (polygon). I also have some points that I
hope to plot them to the city map. The only information I have about those
points are their relative longitude and latitude to the city center by
miles. Is there a way that R can help me to do this? Thanks.
Gary
[[alternative HTML version deleted]]
2004 Nov 14
2
Exporting to file: passing source name to file name in loop
Hi,
I'm having a mental block as to how I can automatically assign filenames
to the output of the following code. I am wishing to create a separate
.png file for every image created, each of them having a sequential
filename ie "sourcefile_index.png" so that I can create a movie from
them.
Please could someone tell me where I am going wrong?
the following code works fine and
2012 Apr 05
2
indexing data.frame columns
Consider the data.frame:
df <- data.frame(A = c(1,4,2,6,7,3,6), B= c(3,7,2,7,3,5,4), C =
c(2,7,5,2,7,4,5), index = c("A","B","A","C","B","B","C"))
I want to select the column specified in 'index' for every row of 'df', to
get
goal <- c(1, 7, 2, 2, 3, 5, 5)
This sounds a lot like the indexing-by-a-matrix
2018 Aug 13
2
substitute() on arguments in ellipsis ("dot dot dot")?
Interestingly,
as.list(substitute(...()))
also works.
On Sun, Aug 12, 2018 at 1:16 PM, Duncan Murdoch
<murdoch.duncan at gmail.com> wrote:
> On 12/08/2018 4:00 PM, Henrik Bengtsson wrote:
>>
>> Hi. For any number of *known* arguments, we can do:
>>
>> one <- function(a) list(a = substitute(a))
>> two <- function(a, b) list(a = substitute(a), b =