If when you say "in Rstudio" you mean the option via the menu (Tools > Import Dataset), it is not possible. This menu just creates a snippet to read the data according to the parameters you configure.
As @carlosfigueira mentioned, what you need is the transposition function, t()
. After reading just be careful with column names and object type.
You’ll have to read with header = FALSE
, and then make some modifications to the data.frame read to leave it in the correct form. I also recommend using stringsAsFactors = FALSE
. For example, considering that you saved the spreadsheet in csv from MS Excel in English:
csvtext <- "Var1;1,2;1,5;1,6
Var2;2;4;6
Var3;7;8;9,2"
dat1 <- read.csv2(text = csvtext, header = FALSE, stringsAsFactors = FALSE)
# Você usaria read.csv2(file = "pasta/arquivo.csv", ...)
dat2 <- t(dat1[, -1])
dat3 <- as.data.frame(dat2)
rownames(dat3) <- NULL
colnames(dat3) <- dat1[, 1]
dat3
# Var1 Var2 Var3
# 1.2 2 7.0
# 1.5 4 8.0
# 1.6 6 9.2
str(dat3)
#'data.frame': 3 obs. of 3 variables:
# $ Var1 : num 1.2 1.5 1.6
# $ Var2: num 2 4 6
# $ Var3: num 7 8 9.2
Although it is strongly recommended to change the form of data acquisition, if possible. This organization is not standard "R", it is the most common in data organization.
You can read the spreadsheet, and then use the function
t
(transpose) to convert from rows to columns.– carlosfigueira