Displaying 20 results from an estimated 700 matches similar to: "Adding columns to dataframe"
2008 May 14
2
Dividing Two Dataframes
Hi,
I have two dataframes one with 144 rows and 160 columns (SDF1) and one with
12 rows and 160 columns (SDF2).
Now I'm trying to divide rows 1:12 with SDF2, rows 13:24 with SDF2, rows
25:36 with SDF 2, .
In S-Plus the following code works fine:
DFS = SDF1[1:144,1:60] / as.vector(SDF2[1:12,1:160])
but in R when I try to implement the formula I get the following error:
"/
2012 Oct 14
3
Pivot Table "like" structure
HI Team,
I am currently working on problem and stumped on "for" loop.
Data:
structure(list(Coutry = structure(c(3L, 3L, 3L, 3L, 2L, 2L, 1L,
1L), .Label = c("J", "M", "U"), class = "factor"), State = structure(c(1L,
1L, 4L, 2L, 5L, 5L, 3L, 6L), .Label = c("A", "C", "K", "O", "S",
2003 Sep 02
3
How to avoid automatic coercion to factor?
I have a function that manipulates a list of numeric and character
components of equal length and wants to return a data.frame.
EG,
f<-function() {
a<-list(Int1=1:5,Char1=letters[1:5],Char2=letters[6:10])
b<-data.frame(a)
}
How can I get the columns Char1, Char2, (...CharN) returned coerced to
character and not factor?
It appears that I could coerce individual columns by
2012 Nov 26
1
error in plot(table(c('a','a')))
Hi all,
there appears to be something strange with the plotting of tables of 1
dimension; if I attempt to make a plot of a table of characters with only
1 value I get an error (Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ). With more than one value I don't get
errors, neither with integers (even if only 1 value):
tbl.char1 <-
2012 Nov 26
1
error in plot(table(c('a','a')))
Hi all,
there appears to be something strange with the plotting of tables of 1
dimension; if I attempt to make a plot of a table of characters with only
1 value I get an error (Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ). With more than one value I don't get
errors, neither with integers (even if only 1 value):
tbl.char1 <-
2018 Jan 08
2
Replace NAs in split lists
Thank you Jeff. Your code works, as usual , perfectly. I am just
wondering why if i put the whole code in one line, i get an error
message.
sdf2 <- lapply( sdf, function(z){z$Value
<-ifelse(is.na(z$Value),z$Value[!is.na(z$Value)][1],z$Value)z})
error. unexpected symbol in sdf2
Thanks again
EK
On Mon, Jan 8, 2018 at 3:12 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:
>
2018 Jan 08
3
Replace NAs in split lists
Why do you want to modify df1?
Why not just reassemble the parts as a new data frame and use that going forward in your calculations? That is generally the preferred approach in R so you can re-do your calculations easily if you find a mistake later.
--
Sent from my phone. Please excuse my brevity.
On January 7, 2018 7:35:59 PM PST, Ek Esawi <esawiek at gmail.com> wrote:
>I just came
2018 Jan 08
0
Replace NAs in split lists
I don't know. You seem to be posting in HTML so your code is mangled. Can you post plain text and use the reprex package to make sure it produces the errorin a clean R session?
--
Sent from my phone. Please excuse my brevity.
On January 8, 2018 8:03:45 AM PST, Ek Esawi <esawiek at gmail.com> wrote:
>Thank you Jeff. Your code works, as usual , perfectly. I am just
>wondering why
2018 Jan 08
1
Replace NAs in split lists
OPS! Sorry i did indeed posted the code in HTML; should have known better.
ifelse(is.na(z$Value),z$Value[!is.na(z$Value)][1],z$Value)z})
error. unexpected symbol in sdf2
On Mon, Jan 8, 2018 at 11:44 AM, Jeff Newmiller
<jdnewmil at dcn.davis.ca.us> wrote:
> I don't know. You seem to be posting in HTML so your code is mangled. Can you post plain text and use the reprex package to
2018 Jan 08
0
Replace NAs in split lists
Upon closer examination I see that you are not using the split version of
df1 as I usually would, so here is a reproducible example:
#----
df1 <- read.table( text=
"ID ID_2 Firist Value
1 a aa TRUE 2
2 a ab FALSE NA
3 a ac FALSE NA
4 b aa TRUE 5
5 b ab FALSE NA
", header=TRUE, as.is=TRUE )
sdf <- split( df1, df1$ID )
# note the extra [ 1 ]
2009 Apr 03
1
Discriminant Analysis - Obtaining Classification Functions
Hello!
I need some help with the linear discriminant analysis in R.
I have some plant samples (divided into several groups) on which I
measured a few quantitative characteristics. Now, I need to infer some
classification rules usable for identifying new samples.
I have used the function lda from the MASS library in a usual fashion:
lda.1 <- lda(groups~char1+char2+char3, data=xxx)
I'd
2018 Jan 08
2
Replace NAs in split lists
Hi
With the example, na.locf seems to be the easiest way.
> library(zoo)
> na.locf(df1)
ID ID_2 Firist Value
1 a aa TRUE 2
2 a ab FALSE 2
3 a ac FALSE 2
4 b aa TRUE 5
5 b ab FALSE 5
Cheers
Petr
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Jeff
> Newmiller
> Sent: Monday, January
2018 Jan 08
2
Replace NAs in split lists
You can enforce these assumptions by sorting on multiple columns, which
leads to
na.locf(df1[ order(df1$ID,df1$Value), ])
On Mon, Jan 8, 2018 at 4:19 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us>
wrote:
> Yes, you are right if the IDs are always sequentially-adjacent and the
> first non-NA value appears in the first record for each ID.
> --
> Sent from my phone. Please
2018 Jan 08
0
Replace NAs in split lists
Yes, you are right if the IDs are always sequentially-adjacent and the first non-NA value appears in the first record for each ID.
--
Sent from my phone. Please excuse my brevity.
On January 8, 2018 2:29:40 AM PST, PIKAL Petr <petr.pikal at precheza.cz> wrote:
>Hi
>
>With the example, na.locf seems to be the easiest way.
>> library(zoo)
>
>> na.locf(df1)
> ID
2010 May 05
2
readLines with space-delimiter?
Hi,
I am reading a large space-delimited text file into R (41 columns and many
rows) and need to do run each row's values through another R object and then
write to another text file. So, far using readLines and writeLines seems to
be the best bet. I've gotten the data exchange working except each row is
read in as one 'chunk', meaning the row has all values between two quotes
2018 Jan 08
0
Replace NAs in split lists
"Enforce" is overstating it... results will differ if there are no non-NA values for a given ID, and there is a potential further discrepancy if there are multiple non-NA values. But these issues were not identified by the OP, so may not be relevant in their case.
--
Sent from my phone. Please excuse my brevity.
On January 8, 2018 6:41:33 AM PST, Eric Berger <ericjberger at
2011 May 08
3
%in% operator - NOT IN
Hello everyone,
I am attempting to use the %in% operator with the ! to produce a NOT IN type
of operation. Why does this not work? Suggestions?
> data2[data1$char1 %in% c("string1","string2"),1]<-min(data1$x1)
> data2[data1$char1 ! %in% c("string1","string2"),1]<-max(data1$x1)+1000
Error: unexpected '!' in "data2[data1$char1
2013 Sep 05
3
[PATCH v2 0/3] btrfs-progs: prevent mkfs from aborting with small volume
Here are 3 patches to avoid undesired aborts of mkfs.btrfs.
These are based on top of Chris''s btrfs-progs.git:
git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git
Thanks,
H.Seto
Hidetoshi Seto (3):
btrfs-progs: error if device for mkfs is too small
btrfs-progs: error if device have no space to make primary chunks
btrfs-progs: calculate available
2019 Jul 08
2
Server fails to boot
First some history. This is an Intel MB and processor some 6 years old,
initially running CentOS 6. It has 4 x 1TB sata drives set up in two
mdraid 1 mirrors. It has performed really well in a rural setting with
frequent power cuts which the UPS has dealt with and auto shuts down the
server after a few minutes and then auto restarts when power is restored.
The clients needed a Windoze server
2004 Nov 23
3
Problem with read.xport() from foreigh package (PR#7389)
Full_Name: Ruskin Chow
Version: R 2.0.1
OS: Windows 2000
Submission from: (NULL) (203.169.154.66)
Data imported from SAS using read.xport() in package foreign are converted to
<NA> when the SAS data field consists of character strings that are only one
character long.
This is apparently a previously reported bug and perhaps fixed in some platform
other than Windows (rw2001).Some