Displaying 20 results from an estimated 20000 matches similar to: "Empty data frame does not maintain column type"
2020 Mar 29
2
is.vector could handle AsIs class better
Dear R-devel,
AsIs class seems to be well handled by `typeof` and `mode` function.
Those two functions are being referred when explaining `is.vector`
behaviour in manual. Yet `is.vector` does not seem to be handling AsIs
class the same way.
is.vector(1L)
#[1] TRUE
is.vector(I(1L))
#[1] FALSE
Is there any reason behind this behaviour?
Could we have it supported so AsIs class is ignored when
2019 Jul 18
2
inconsistent behaviour of c(...)
Greetings,
Running R 3.5.0 under Windows 7
typeof(c(1,"2")) yields "character" as expected. But in
d.f <- data.frame(C=c(1,"2"))
typeof(d.f$C) yields "integer".
Is this a bug?
Michael Meyer
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:
2020 Mar 30
1
is.vector could handle AsIs class better
Thank you Gabriel,
Agree, although I think that could be relaxed in this single case and
AsIs class could be ignored.
Best,
Jan
On Sun, Mar 29, 2020 at 7:09 PM Gabriel Becker <gabembecker at gmail.com> wrote:
>
> Jan,
>
> I believe it's because it has "a non-NULL attribute other than names" as per the documentation. In this case its class of "AsIs".
>
2017 Jul 08
2
Factor vs character in a data.frame vs vector
Thanks Marc. It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame.? I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely.
On Friday, July 7, 2017, 10:37:29 AM EDT, Marc Schwartz <marc_schwartz at me.com> wrote:
> On Jul 7, 2017, at 6:03
2008 Nov 17
2
stringsAsFactors = FALSE
Hi all,
I love the option to not automatically convert strings into factors,
but there are three places that the current option doesn't work where
I think it should:
options(stringsAsFactors = FALSE)
str(expand.grid(letters))
str(type.convert(letters))
df <- read.fwf(textConnection(paste(letters,collapse="\n")), 1)
str(df)
I think type.convert and read.fwf can be fixed by
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:
>
2017 Jul 08
0
Factor vs character in a data.frame vs vector
> On Jul 7, 2017, at 7:03 PM, John Kane <jrkrideau at yahoo.ca> wrote:
>
> Thanks Marc.
> It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame. I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely.
Welcome John.
Going back to
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
2009 Mar 31
1
as.data.frame peculiarities
The documentation of as.data.frame is not explicit about how it generates
column names for the simple vector case, but it seems to use the character
form of the quoted argument, e.g.
names(as.data.frame(1:3))
[1] "1:3"
But there is a strange case:
names(as.data.frame(c("a")))
[1] "if (stringsAsFactors) factor(x) else x"
I feel fairly comfortable calling this a
2017 Jul 07
0
Factor vs character in a data.frame vs vector
> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <r-help at r-project.org> wrote:
>
> This is not serious problem but I just wonder if someone can explain what is happening.
> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character. It's probably something simple that I have read and forgotten but I thought I'd ask.
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"
2006 Aug 18
5
as.data.frame(cbind()) transforming numeric to factor?
Dear List,
why does as.data.frame(cbind()) transform numeric variables to
factors, once one of the other variablesused is a character vector?
#
x.1 <- rnorm(10)
x.2 <- c(rep("Test",10))
Foo <- as.data.frame(cbind(x.1))
is.factor(Foo$x.1)
Foo <- as.data.frame(cbind(x.1,x.2))
is.factor(Foo$x.1)
#
I assume there is a good reason for this, can somebody explain? Thanks.
Best,
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
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"
2016 Mar 01
2
Data frame printing buglet when multiple empty column names
This is admittedly minor, and you shouldn't have repeated names in a
data frame anyway, but:
df <- data.frame(1:3, 1:3, 1:3)
# Ok
setNames(df, c("x", "y", ""))
# Not ok
setNames(df, c("x", "", ""))
Hadley
--
http://hadley.nz
2003 Feb 12
2
rbind.data.frame: character comverted to factor
Dear All,
on rbind:ing together a number of data.frames, I found that
character variables are converted into factors. Since this
occurred for a data identifier, it was a little inconvenient
and, to me, unexpected. (The help page explains the
general procedure used. I also found that on forming
a data frame, character variables are converted to factors.
The help page on read.table has the
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
2005 Mar 17
1
Binding one column of characters into a dataframe factors other numeric columns
Hi all,
I searched through the archives, but couldn't find a fix...
Basically, I've got a bunch of numeric vectors and one character vector that
I want to bind into a data frame. When I include the character vector as a
column in the data frame, all the numeric columns get factored in the data
frame, which makes it tough to call those columns for calculations later on.
I've tried
2013 Jun 10
4
Combining CSV data
Hello R community,
I am trying to combine two CSV files that look like this:
File A
Row_ID_CR, Data1, Data2, Data3
1, aa, bb, cc
2, dd, ee, ff
File B
Row_ID_N, Src_Row_ID, DataN1
1a, 1, This is comment 1
2a, 1, This is comment 2
3a,