Concatenating column when should only read an input

Asked

Viewed 63 times

1

I’m using the following code:

library(data.table)

setwd("/home/andre/monografia/") ; getwd()

obj = read.csv(file = "Grup1C0.csv");

tes = obj[4,4]

View(tes)

The road that is in position [4,4] of the object obj is a string 45 characters, but when I check what was the value assigned to the object tes I have as a result all the entries of column 4 in a single vector.

How do I have only the string of my interest in tes?

  • André, try creating a reproducible example, as it is not possible to replicate your example. If obj for a data.frame it will return the value of row 4 column 4. If obj for a data.table it will return the value "4". In either case the result would be all the values in column 4.

1 answer

2

I solved the problem by changing the function read.csv. Follow the line for example:

Grup1C0 <- read.csv("~/monografia/Grup1C0.csv", row.names=1, stringsAsFactors=FALSE)

The argument is really important, is the StringAsFactors.

  • André, I’m glad you solved the problem. However it doesn’t seem clear how this happened, since this attribute StringAsFactors does not seem to be related to your problem. Could elaborate better what has changed, please?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.