There is a table which I read in R.

data <- read.table("lab4_1.csv", sep=";", dec=",", header=TRUE,row.names=1, col.names = c("ПІБ", "Атестат", "Фізика", "Математика", "Укр.М.")) data dat = c(data[,2],data[,3],data[,4]) dat 

Here is a piece of data: data

And this is what it puts in dat: dat

datshort

At the very beginning it is already clear that the numbers are not at all what they were in data. Information on R. on the Internet is not enough, can someone tell me why it puts these numbers and how to make the necessary columns? I can not understand what is the error.

PS: I tried to make a table with names (the first column is not the name of the rows, but a separate column with values) and enter only it in the same way. Names changed to a set of numbers, it is not known from where taken.

  • but give the result of typeof (data) and summary (data). I suspect that the numbers have swayed with symbols and turned into factors. - Yury Arrow

1 answer 1

1) Add stringsAsFactors =FALSE to read.table to read the text as text. Usually, by default, R reads it as a factor.

2) I think the problem can also be in dec = ",", do you have exactly the comma of the fractional separator?

3) If all of the above does not help, try making as.numeric(data[,2]) or as.numeric(as.character(data[,2])) - if the problem in the number format and delimiters works.

  • Yes, all the same, I did not pay attention to the fraction separator. Although I checked the table, I did not even look at the separator. Corrected to the point and everything worked fine. Thanks for the answer, I hope I will not make such a mistake again. Good luck with prof. activities;) - Vladimir
  • 2
    I will add that so dat = c(data[,2],data[,3],data[,4]) not necessary. You can unname(unlist(data[, 2:4])) or unname(do.call(c, data[, 2:4])) - Ogurtsov