Displaying 20 results from an estimated 20000 matches similar to: "inconsistent behaviour of c(...)"
2019 Jul 19
2
inconsistent behaviour of c(...)
Hello,
A way to see this is with ?class
# OP's code
typeof(c(1,"2")) # "character"
d.f <- data.frame(C=c(1,"2"))
typeof(d.f$C) # "integer"
# And check the objects' classes
class(c(1,"2")) # "character"
class(d.f$C) # "factor"
Hope this helps,
Rui Barradas
?s 08:19 de 19/07/19, Peter Langfelder escreveu:
2010 Oct 06
3
Empty data frame does not maintain column type
Does anyone know why a data frame created with empty character columns
converts them to integer columns?
> df<-data.frame(a=character(0),b=character(0))
> df<-rbind(df,c("a","a"))
> typeof(df[1,1])
[1] "integer"
AsIs doesn't help:
> df<-data.frame(a=I(character(0)),b=I(character(0)))
> df<-rbind(df,I(c("a","a")))
2014 Apr 02
3
Typeof for character vector in dataframe returns integer
Hi ,
I want to know is this behavior expected and why is that ? Need some help
gender <- c("F", "M", "M", "F", "F", "M", "F", "F")
> age <- c(23, 25, 27, 29, 31, 33, 35, 37)
> df<- data.frame(gender,age)
> typeof(df[[1]])
[1] "integer"
2009 Feb 27
2
factors to integers preserving value in a dataframe
I want to produce a dataframe with integer columns for elements of
string pairs:
pairs <- c("10 21","23 45")
pairs.split <- lapply(pairs,function(x)strsplit(x," "))
pdf <- as.data.frame(pairs.split)
names(pdf) <- c("p","q")
-- at this point things look good, except the columns are factors, as
I didn't change the default
2010 Apr 30
3
Why do data frame column types vary across apply, lapply?
Hi,
I still have little ability to predict how these functions will treat the
columns of data frames:
> # Here's a data frame with a column "a" of integers,
> # and a column "b" of characters:
> df <- data.frame(
+ a = 1:2,
+ b = c("a","b")
+ )
> df
a b
1 1 a
2 2 b
>
> # Except -- both columns are characters:
>
2009 Aug 17
1
R : how does %in% operator work?
*Problem-1*
CASE-I---------(works fine)
> var1<-"tom"
> var1
[1"tom"
> var1<-as.character(var1)
> var1
[1] "tom"
> var2<-c("tom","harry","kate")
> logc<-(var1 %in% var2)
> logc
[1] TRUE
> typeof(var1)
[1] "character"
> typeof(var2)
[1] "character"
2005 Oct 27
3
Strange behaviour of type conversion (PR#8256)
Where is my error??
I have a strange behaviour in R, looks like type conversions are messed =
up.
Maybe i just make a stupid mistake, but help would be appreciated.
To reproduce:
expected:
> typeof(3)
[1] "double"
> as.integer(3)
[1] 3
> typeof((0.3/0.1))
[1] "double"
!!!! strange:
> as.integer((0.3/0.1))
[1] 2
also for trunc:
>trunc(c(5,7))
[1] 5 7
2017 Dec 07
2
parallel computing with foreach()
I have used foreach() for parallel computing but in the current problem, it
is not working. Given the volume and type of the data involved in the
analysis, I will try to give below the complete code without reproducible
example.
In short, each R environment will draw a set of separate files, perform the
analysis and dump in separate folders.
splist <- c("juoc", "juos",
2007 Nov 02
1
counting with factors
Hi there,
I have something that appears to be a factor called drug:
Typeof(drug) => Integer
As.numeric(drug) gives a long list
Levels(drug) gives a long list, too.
Now I want something like the summary function does:
I want to count how often each level occurs in the given vector.
My problem is that summary gives me a list with counts that is incomplete
and adds the
2017 Dec 07
0
parallel computing with foreach()
Your code generates an error that has nothing to do with dopar. I have
no idea what your function stack is supposed to do; you may be
inadvertently calling utils::stack which would produce this kind of
error:
> stack(1:25, RAT = FALSE)
Error in data.frame(values = unlist(unname(x)), ind, stringsAsFactors = FALSE) :
arguments imply differing number of rows: 25, 0
HTH,
Peter
On Wed, Dec 6,
2012 Aug 17
5
Opinion: Why I find factors convenient to use
Folks:
Over the years, many people -- including some who I would consider
real expeRts -- have criticized factors and advocated the use
(sometimes exclusively) of character vectors instead. I would just
like to point out that, for me, factors provide one feature that I
find to be very convenient: ordering of levels. **
As an example, suppose one has a character vector of labels
2011 Feb 28
1
Data type problem when extract data from SQLite to R by using RSQLite
Hi there,
When I extract data from SQLite to R, the data types (or modes) of the
extracted data seems to be determined by the value of the first row.
Please see the following example.
When I put the missing values first, the column extracted is of the
mode character.
> str(dbGetQuery(sql.industry,
+ "select pya_var from annual_data3
+ order by
2013 Jan 22
1
c(), rbind and cbind functions - why type of resulting object is double
Hello Everyone,
I am using R 2.15.0 and I came across this behaviour and I was wondering
why I don't get an integer vector or and integer matrix with the following
code:
> z <- c(1, 2:0, 3, 4:8)
> typeof(z)
[1] "double"
> z <- rbind(1, 2:0, 3, 4:8)
Warning message:
In rbind(1, 2:0, 3, 4:8) :
number of columns of result is not a multiple of vector length (arg
2008 Nov 27
2
as.numeric in data.frame, but only where it is possible
Hi,
I would like to convert my "character" sequences in my matrix/
data.frame into "numeric" where it is possible.
I would also like to retain my alphabetic character strings in their
original forms.
"5.1" > 5.1
"hm" > "hm"
k<-matrix(c("aa", "bb", 1,2, 4.3, 0), nrow=2)
mode(k) <- "numeric"
#
2020 Jun 30
2
[PATCH 18/18] arm64: lto: Strengthen READ_ONCE() to acquire when CLANG_LTO=y
On Tue, Jun 30, 2020 at 7:39 PM Will Deacon <will at kernel.org> wrote:
> +#define __READ_ONCE(x) \
> +({ \
> + int atomic = 1; \
> + union { __unqual_scalar_typeof(x) __val; char __c[1]; } __u; \
> +
2020 Jun 30
2
[PATCH 18/18] arm64: lto: Strengthen READ_ONCE() to acquire when CLANG_LTO=y
On Tue, Jun 30, 2020 at 7:39 PM Will Deacon <will at kernel.org> wrote:
> +#define __READ_ONCE(x) \
> +({ \
> + int atomic = 1; \
> + union { __unqual_scalar_typeof(x) __val; char __c[1]; } __u; \
> +
2012 Apr 03
2
how to map microarray probe to gene, homology
Hi:
I have clustered microarray gene expression data and trying to map between
microarray probe, gene, pathway, gene ontology, and homology for a set of
(affy) microarray probes. Is there any package in R which facilitates this?
I am looking at bioconductor, but till now could not find a solution. A
link to some worked example would be appreciated.
Thanks and regards.
John
[[alternative HTML
2004 Sep 08
4
factor always have type integer
typeof applied to a factor always seems to return "integer",
independently of the type of the levels.
This has a strange side effect.
When a variable is "imported" into a data frame,
its type changes.
character variables automatically are converted
to factors when imported into data frames.
Here is an example:
> v1<-1:3
>
2011 Aug 07
2
[PATCH] kinit minor checkpatch cleanup
coding style fixes.
FIXME: check that compiled bin the same1!!
---
usr/kinit/initrd.c | 3 ++-
usr/kinit/kinit.c | 12 ++++--------
usr/kinit/kinit.h | 20 ++++++++++----------
usr/kinit/name_to_dev.c | 6 +++---
usr/kinit/nfsroot.c | 5 ++---
5 files changed, 21 insertions(+), 25 deletions(-)
diff --git a/usr/kinit/initrd.c b/usr/kinit/initrd.c
index
2019 May 23
4
[RFC][PATCH] kernel.h: Add generic roundup_64() macro
On Thu, 23 May 2019 08:10:44 -0700
Linus Torvalds <torvalds at linux-foundation.org> wrote:
> On Thu, May 23, 2019 at 7:00 AM Steven Rostedt <rostedt at goodmis.org> wrote:
> >
> > +# define roundup_64(x, y) ( \
> > +{ \
> > + typeof(y) __y = y;