thmsfuller066 at gmail.com
2010-Aug-02 01:48 UTC
[R] Why do the results of paste() depend on how the argument (data.frame) is constructed?
Hi, The following two 'df's should be the same, although their constructions are different. But the results of paste() are different. I don't see this is explained in ?paste. Could you help me understand why it is like this?> df=data.frame(X=c(1, 2, 3), Y=c(4, 5, 6)) > dfX Y 1 1 4 2 2 5 3 3 6> paste(df)[1] "c(1, 2, 3)" "c(4, 5, 6)"> df=data.frame(X=1:3, Y=4:6) > dfX Y 1 1 4 2 2 5 3 3 6> paste(df)[1] "1:3" "4:6">-- Tom
Erik Iverson
2010-Aug-02 03:48 UTC
[R] Why do the results of paste() depend on how the argument (data.frame) is constructed?
On 08/01/2010 08:48 PM, thmsfuller066 at gmail.com wrote:> Hi, > > The following two 'df's should be the same, although their > constructions are different.But they aren't the same. df1 <- data.frame(X=c(1, 2, 3), Y=c(4, 5, 6)) df2 <- data.frame(X=1:3, Y=4:6) identical(df1, df2) yields FALSE See str(df1) str(df2) to see how they differ. But the results of paste() are different.> I don't see this is explained in ?paste. Could you help me understand > why it is like this? > >> df=data.frame(X=c(1, 2, 3), Y=c(4, 5, 6)) >> df > X Y > 1 1 4 > 2 2 5 > 3 3 6 >> paste(df) > [1] "c(1, 2, 3)" "c(4, 5, 6)" >> df=data.frame(X=1:3, Y=4:6) >> df > X Y > 1 1 4 > 2 2 5 > 3 3 6 >> paste(df) > [1] "1:3" "4:6" >> > >
S Ellison
2010-Aug-02 13:04 UTC
[R] Why do the results of paste() depend on how the argument (data.frame) is constructed?
At the risk of repeating a post I haven't read, the two constructs are different because 1:3 returns a vector of integers (class "integer") and c(1, 2, 3) is a bit more conservative about what '1' and the like mean and returns a vector of class "numeric". lapply(df1, class) lapply(df2, class) On 08/01/2010 08:48 PM, thmsfuller066 at gmail.com wrote:> Hi, > > The following two 'df's should be the same, although their > constructions are different.But they aren't the same. df1 <- data.frame(X=c(1, 2, 3), Y=c(4, 5, 6)) df2 <- data.frame(X=1:3, Y=4:6) identical(df1, df2) yields FALSE See str(df1) str(df2) to see how they differ. But the results of paste() are different.> I don't see this is explained in ?paste. Could you help me understand > why it is like this? > >> df=data.frame(X=c(1, 2, 3), Y=c(4, 5, 6)) >> df > X Y > 1 1 4 > 2 2 5 > 3 3 6 >> paste(df) > [1] "c(1, 2, 3)" "c(4, 5, 6)" >> df=data.frame(X=1:3, Y=4:6) >> df > X Y > 1 1 4 > 2 2 5 > 3 3 6 >> paste(df) > [1] "1:3" "4:6" >> > >______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
Apparently Analagous Threads
- indexing into a data.frame using another data.frame that also contains values for replacement
- Why is any() only defined for a numeric and not logical data.frame?
- SQLDF column errors
- Strange names when creating a data.frame: Difference between <- and =
- Best way/practice to create a new data frame from two given ones with last column computed from the two data frames?